1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #32012 -- Made test database creation sync apps models when migrations are disabled.

Thanks Jaap Roes for the report.
This commit is contained in:
Mariusz Felisiak
2020-09-23 10:54:04 +02:00
committed by GitHub
parent 7b9596b974
commit 77caeaea88
8 changed files with 74 additions and 6 deletions

View File

@@ -58,7 +58,14 @@ class BaseDatabaseCreation:
settings.DATABASES[self.connection.alias]["NAME"] = test_database_name
self.connection.settings_dict["NAME"] = test_database_name
if self.connection.settings_dict['TEST']['MIGRATE']:
try:
if self.connection.settings_dict['TEST']['MIGRATE'] is False:
# Disable migrations for all apps.
old_migration_modules = settings.MIGRATION_MODULES
settings.MIGRATION_MODULES = {
app.label: None
for app in apps.get_app_configs()
}
# We report migrate messages at one level lower than that
# requested. This ensures we don't get flooded with messages during
# testing (unless you really ask to be flooded).
@@ -69,6 +76,9 @@ class BaseDatabaseCreation:
database=self.connection.alias,
run_syncdb=True,
)
finally:
if self.connection.settings_dict['TEST']['MIGRATE'] is False:
settings.MIGRATION_MODULES = old_migration_modules
# We then serialize the current state of the database into a string
# and store it on the connection. This slightly horrific process is so people