Ticket #5896: 5896.diff

File 5896.diff, 2.1 KB (added by arien <regexbot@…>, 16 years ago)
  • docs/model-api.txt

     
    20692069to populate default records, or create SQL functions, automatically.
    20702070
    20712071The hook is simple: Django just looks for a file called
    2072 ``<appname>/sql/<modelname>.sql``, where ``<appname>`` is your app directory and
     2072``<appname>/<modelname>.sql``, where ``<appname>`` is your app directory and
    20732073``<modelname>`` is the model's name in lowercase.
    20742074
    20752075In the ``Person`` example model at the top of this document, assuming it lives
    20762076in 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::
    20782078
    20792079    INSERT INTO myapp_person (first_name, last_name) VALUES ('John', 'Lennon');
    20802080    INSERT INTO myapp_person (first_name, last_name) VALUES ('Paul', 'McCartney');
     
    20992099
    21002100There's also a hook for backend-specific SQL data. For example, you can have
    21012101separate initial-data files for PostgreSQL and MySQL. For each app, Django
    2102 looks for a file called ``<appname>/sql/<modelname>.<backend>.sql``, where
     2102looks for a file called ``<appname>/<modelname>.<backend>.sql``, where
    21032103``<appname>`` is your app directory, ``<modelname>`` is the model's name in
    21042104lowercase and ``<backend>`` is the value of ``DATABASE_ENGINE`` in your
    21052105settings file (e.g., ``postgresql``, ``mysql``).
    21062106
    2107 Backend-specific SQL data is executed before non-backend-specific SQL data. For
    2108 example, if your app contains the files ``sql/person.sql`` and
    2109 ``sql/person.postgresql.sql`` and you're installing the app on PostgreSQL,
    2110 Django will execute the contents of ``sql/person.postgresql.sql`` first, then
    2111 ``sql/person.sql``.
     2107Backend-specific SQL data is executed before non-backend-specific SQL data.
     2108For example, if your app contains the files ``person.sql`` and
     2109``person.postgresql.sql`` and you're installing the app on PostgreSQL, Django
     2110will execute the contents of ``person.postgresql.sql`` first, then
     2111``person.sql``.
Back to Top