mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
[1.2.X] Fixed #14799 -- Provided a full solution for test database creation order problems.
Backport of r14822, r14823 and r14824 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14825 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -422,6 +422,53 @@ will be redirected to point at ``default``. As a result, writes to
|
||||
the same database, not because there is data replication between the
|
||||
two databases.
|
||||
|
||||
.. _topics-testing-creation-dependencies:
|
||||
|
||||
Controlling creation order for test databases
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. versionadded:: 1.2.4
|
||||
|
||||
By default, Django will always create the ``default`` database first.
|
||||
However, no guarantees are made on the creation order of any other
|
||||
databases in your test setup.
|
||||
|
||||
If your database configuration requires a specific creation order, you
|
||||
can specify the dependencies that exist using the
|
||||
:setting:`TEST_DEPENDENCIES` setting. Consider the following
|
||||
(simplified) example database configuration::
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
# ... db settings
|
||||
'TEST_DEPENDENCIES': ['diamonds']
|
||||
},
|
||||
'diamonds': {
|
||||
# ... db settings
|
||||
},
|
||||
'clubs': {
|
||||
# ... db settings
|
||||
'TEST_DEPENDENCIES': ['diamonds']
|
||||
},
|
||||
'spades': {
|
||||
# ... db settings
|
||||
'TEST_DEPENDENCIES': ['diamonds','hearts']
|
||||
},
|
||||
'hearts': {
|
||||
# ... db settings
|
||||
'TEST_DEPENDENCIES': ['diamonds','clubs']
|
||||
}
|
||||
}
|
||||
|
||||
Under this configuration, the ``diamonds`` database will be created first,
|
||||
as it is the only database alias without dependencies. The ``default``` and
|
||||
``clubs`` alias will be created next (although the order of creation of this
|
||||
pair is not guaranteed); then ``hearts``; and finally ``spades``.
|
||||
|
||||
If there are any circular dependencies in the
|
||||
:setting:`TEST_DEPENDENCIES` definition, an ``ImproperlyConfigured``
|
||||
exception will be raised.
|
||||
|
||||
Other test conditions
|
||||
---------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user