diff --git a/tests/migration_test_data_persistence/migrations/0002_add_book.py b/tests/migration_test_data_persistence/migrations/0002_add_book.py
index 6ce7fff..9b6e617 100644
a
|
b
|
from django.db import migrations
|
5 | 5 | |
6 | 6 | |
7 | 7 | def add_book(apps, schema_editor): |
8 | | apps.get_model("migration_test_data_persistence", "Book").objects.using( |
9 | | schema_editor.connection.alias, |
10 | | ).create( |
| 8 | if schema_editor.connection.alias != 'default': |
| 9 | return |
| 10 | apps.get_model("migration_test_data_persistence", "Book").objects.create( |
11 | 11 | title="I Love Django", |
12 | 12 | ) |
13 | 13 | |
diff --git a/tests/routers.py b/tests/routers.py
index e69de29..c71ec60 100644
a
|
b
|
|
| 1 | APPS_ON_OTHER_DATABASE = { |
| 2 | # Contrib apps |
| 3 | 'auth', |
| 4 | 'contenttypes', |
| 5 | 'sites', |
| 6 | # Test apps |
| 7 | 'multiple_database', |
| 8 | 'prefetch_related', |
| 9 | } |
| 10 | |
| 11 | class DjangoTestSuiteRouter(object): |
| 12 | |
| 13 | def db_for_read(self, model, **hints): |
| 14 | return None |
| 15 | |
| 16 | def db_for_write(self, model, **hints): |
| 17 | return None |
| 18 | |
| 19 | def allow_relation(self, obj1, obj2, **hints): |
| 20 | return None |
| 21 | |
| 22 | def allow_migrate(self, db, model): |
| 23 | """ |
| 24 | Migrate only apps that have tests cases with multi_db = True |
| 25 | on the 'other' database. |
| 26 | """ |
| 27 | if db == 'other': |
| 28 | return model._meta.app_label in APPS_ON_OTHER_DATABASE |
| 29 | return None |
diff --git a/tests/runtests.py b/tests/runtests.py
index f81fe74..80c3b02 100755
a
|
b
|
def setup(verbosity, test_labels):
|
118 | 118 | 'STATIC_URL': settings.STATIC_URL, |
119 | 119 | 'STATIC_ROOT': settings.STATIC_ROOT, |
120 | 120 | 'MIDDLEWARE_CLASSES': settings.MIDDLEWARE_CLASSES, |
| 121 | 'DATABASE_ROUTERS': settings.DATABASE_ROUTERS, |
121 | 122 | } |
122 | 123 | |
123 | 124 | # Redirect some settings for the duration of these tests. |
… |
… |
def setup(verbosity, test_labels):
|
149 | 150 | 'auth': 'django.contrib.auth.tests.migrations', |
150 | 151 | 'contenttypes': 'contenttypes_tests.migrations', |
151 | 152 | } |
| 153 | settings.DATABASE_ROUTERS = ['routers.DjangoTestSuiteRouter'] |
152 | 154 | |
153 | 155 | if verbosity > 0: |
154 | 156 | # Ensure any warnings captured to logging are piped through a verbose |