Ticket #5896: 5896.diff
File 5896.diff, 2.1 KB (added by , 17 years ago) |
---|
-
docs/model-api.txt
2069 2069 to populate default records, or create SQL functions, automatically. 2070 2070 2071 2071 The hook is simple: Django just looks for a file called 2072 ``<appname>/ sql/<modelname>.sql``, where ``<appname>`` is your app directory and2072 ``<appname>/<modelname>.sql``, where ``<appname>`` is your app directory and 2073 2073 ``<modelname>`` is the model's name in lowercase. 2074 2074 2075 2075 In the ``Person`` example model at the top of this document, assuming it lives 2076 2076 in an app called ``myapp``, you could add arbitrary SQL to the file 2077 ``myapp/ sql/person.sql``. Here's an example of what the file might contain::2077 ``myapp/person.sql``. Here's an example of what the file might contain:: 2078 2078 2079 2079 INSERT INTO myapp_person (first_name, last_name) VALUES ('John', 'Lennon'); 2080 2080 INSERT INTO myapp_person (first_name, last_name) VALUES ('Paul', 'McCartney'); … … 2099 2099 2100 2100 There's also a hook for backend-specific SQL data. For example, you can have 2101 2101 separate initial-data files for PostgreSQL and MySQL. For each app, Django 2102 looks for a file called ``<appname>/ sql/<modelname>.<backend>.sql``, where2102 looks for a file called ``<appname>/<modelname>.<backend>.sql``, where 2103 2103 ``<appname>`` is your app directory, ``<modelname>`` is the model's name in 2104 2104 lowercase and ``<backend>`` is the value of ``DATABASE_ENGINE`` in your 2105 2105 settings file (e.g., ``postgresql``, ``mysql``). 2106 2106 2107 Backend-specific SQL data is executed before non-backend-specific SQL data. For2108 example, if your app contains the files ``sql/person.sql`` and2109 `` sql/person.postgresql.sql`` and you're installing the app on PostgreSQL,2110 Django will execute the contents of ``sql/person.postgresql.sql`` first, then2111 `` sql/person.sql``.2107 Backend-specific SQL data is executed before non-backend-specific SQL data. 2108 For example, if your app contains the files ``person.sql`` and 2109 ``person.postgresql.sql`` and you're installing the app on PostgreSQL, Django 2110 will execute the contents of ``person.postgresql.sql`` first, then 2111 ``person.sql``.