mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
[soc2009/multidb] Renaming of database attributes - you now use NAME, ENGINE, etc rather than DATABASE_NAME, DATABASE_ENGINE inside DATABASES. Also deprecates the use of short names (.e.g., `sqlite3` for backends in ENGINE). Patch from Russell Keith-Magee.
Conflicts: docs/releases/1.2.txt git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/multidb@11775 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -290,13 +290,13 @@ If you aim to build a database-agnostic application, you should account for
|
||||
differences in database column types. For example, the date/time column type
|
||||
in PostgreSQL is called ``timestamp``, while the same column in MySQL is called
|
||||
``datetime``. The simplest way to handle this in a ``db_type()`` method is to
|
||||
check the ``connection.settings_dict['DATABASE_ENGINE']`` attribute.
|
||||
check the ``connection.settings_dict['ENGINE']`` attribute.
|
||||
|
||||
For example::
|
||||
|
||||
class MyDateField(models.Field):
|
||||
def db_type(self, connection):
|
||||
if connection.settings_dict['DATABASE_ENGINE'] == 'mysql':
|
||||
if connection.settings_dict['ENGINE'] == 'django.db.backends.mysql':
|
||||
return 'datetime'
|
||||
else:
|
||||
return 'timestamp'
|
||||
|
||||
@@ -118,23 +118,27 @@ The SQL files are read by the :djadmin:`sqlcustom`, :djadmin:`sqlreset`,
|
||||
<ref-django-admin>`. Refer to the :ref:`manage.py documentation
|
||||
<ref-django-admin>` for more information.
|
||||
|
||||
Note that if you have multiple SQL data files, there's no guarantee of the order
|
||||
in which they're executed. The only thing you can assume is that, by the time
|
||||
your custom data files are executed, all the database tables already will have
|
||||
been created.
|
||||
Note that if you have multiple SQL data files, there's no guarantee of
|
||||
the order in which they're executed. The only thing you can assume is
|
||||
that, by the time your custom data files are executed, all the
|
||||
database tables already will have been created.
|
||||
|
||||
Database-backend-specific SQL data
|
||||
----------------------------------
|
||||
|
||||
There's also a hook for backend-specific SQL data. For example, you can have
|
||||
separate initial-data files for PostgreSQL and MySQL. For each app, Django
|
||||
looks for a file called ``<appname>/sql/<modelname>.<backend>.sql``, where
|
||||
``<appname>`` is your app directory, ``<modelname>`` is the model's name in
|
||||
lowercase and ``<backend>`` is the value of ``DATABASE_ENGINE`` for the given
|
||||
database being set up in your settings file (e.g., ``postgresql``, ``mysql``).
|
||||
There's also a hook for backend-specific SQL data. For example, you
|
||||
can have separate initial-data files for PostgreSQL and MySQL. For
|
||||
each app, Django looks for a file called
|
||||
``<appname>/sql/<modelname>.<backend>.sql``, where ``<appname>`` is
|
||||
your app directory, ``<modelname>`` is the model's name in lowercase
|
||||
and ``<backend>`` is the last part of the module name provided for the
|
||||
:setting:`ENGINE` in your settings file (e.g., if you have defined a
|
||||
database with an :setting:`ENGINE` value of
|
||||
``django.db.backends.postgresql``, Django will look for
|
||||
``<appname>/sql/<modelname>.postgresql.sql``).
|
||||
|
||||
Backend-specific SQL data is executed before non-backend-specific SQL data. For
|
||||
example, if your app contains the files ``sql/person.sql`` and
|
||||
``sql/person.postgresql.sql`` and you're installing the app on PostgreSQL,
|
||||
Django will execute the contents of ``sql/person.postgresql.sql`` first, then
|
||||
``sql/person.sql``.
|
||||
Backend-specific SQL data is executed before non-backend-specific SQL
|
||||
data. For example, if your app contains the files ``sql/person.sql``
|
||||
and ``sql/person.postgresql.sql`` and you're installing the app on
|
||||
PostgreSQL, Django will execute the contents of
|
||||
``sql/person.postgresql.sql`` first, then ``sql/person.sql``.
|
||||
|
||||
@@ -19,15 +19,15 @@ Give Django your database parameters
|
||||
|
||||
You'll need to tell Django what your database connection parameters are, and
|
||||
what the name of the database is. Do that by editing the :setting:`DATABASES`
|
||||
setting and assigning values to the following keys in the ``'default'``
|
||||
dictionary:
|
||||
setting and assigning values to the following keys for the ``'default'``
|
||||
connection:
|
||||
|
||||
* ``DATABASE_NAME``
|
||||
* ``DATABASE_ENGINE``
|
||||
* ``DATABASE_USER``
|
||||
* ``DATABASE_PASSWORD``
|
||||
* ``DATABASE_HOST``
|
||||
* ``DATABASE_PORT``
|
||||
* :setting:`NAME`
|
||||
* :setting:`ENGINE`
|
||||
* :setting:`USER`
|
||||
* :setting:`PASSWORD`
|
||||
* :setting:`HOST`
|
||||
* :setting:`PORT`
|
||||
|
||||
Auto-generate the models
|
||||
========================
|
||||
|
||||
Reference in New Issue
Block a user