Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #981 -- documented the SQL initial data insert files.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2942 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 21dd8e272b50c6aba1a08e14ab232b10dcb6e8db 1 parent 026d8c6
Malcolm Tredinnick authored May 19, 2006
11  docs/django-admin.txt
@@ -200,6 +200,9 @@ sqlall [appname appname ...]
200 200
 
201 201
 Prints the CREATE TABLE and initial-data SQL statements for the given appnames.
202 202
 
  203
+Refer to the description of ``sqlinitialdata`` for an explanation of how to
  204
+specify seed data.
  205
+
203 206
 sqlclear [appname appname ...]
204 207
 --------------------------------------
205 208
 
@@ -215,6 +218,14 @@ sqlinitialdata [appname appname ...]
215 218
 
216 219
 Prints the initial INSERT SQL statements for the given appnames.
217 220
 
  221
+This command will read any files under ``<appname>/sql/`` that have the same
  222
+name as the lower-cased version of a model name (so if your app includes a
  223
+model called ``Poll``, the file ``poll.sql`` will be read). These files are
  224
+expected to be valid SQL files and their contents are piped into the database
  225
+after all of the models' table creation statements have been executed. This
  226
+can be used to populate the tables with any necessary initial records or test
  227
+data.
  228
+
218 229
 sqlreset [appname appname ...]
219 230
 --------------------------------------
220 231
 
18  docs/model-api.txt
@@ -1631,3 +1631,21 @@ read, in part::
1631 1631
         'mysite.myapp',
1632 1632
         #...
1633 1633
     )
  1634
+
  1635
+Seeding models with initial data
  1636
+================================
  1637
+
  1638
+Sometimes, once the database tables for a model are created, you will want to
  1639
+populate them with some default records or perhaps some testing data. For each
  1640
+model you have like this, create a file named after the lower-cased version of
  1641
+the model's name, with an extension of ``.sql``. Put this file in a directory
  1642
+called ``sql/`` under your application directory (so, ``myapp/sql/poll.sql``
  1643
+for ``Poll`` model in the ``myapp`` application).
  1644
+
  1645
+This file should contain valid SQL statements that can be executed to create
  1646
+the initial data you would like to insert. These files are read by the
  1647
+``sqlinitialdata``, ``sqlreset``, ``sqlall`` and ``reset`` commands in
  1648
+``manage.py``. Refer to the `manage.py documentation`_ for more
  1649
+information.
  1650
+
  1651
+.. _`manage.py documentation`: http://www.djangoproject.com/documentation/django_admin/#sqlinitialdata-appname-appname

0 notes on commit 21dd8e2

Please sign in to comment.
Something went wrong with that request. Please try again.