mirror of
https://github.com/django/django.git
synced 2025-07-24 05:36:15 +00:00
Fixed #14799 -- Provided a full solution for test database creation order problems.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14822 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
111ed0195e
commit
b11c21d69a
3 changed files with 191 additions and 13 deletions
|
@ -454,6 +454,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.3
|
||||
|
||||
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
|
||||
---------------------
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue