Refs #26552 -- Made reloading the database for tests check only loaded tables constraints.

This commit is contained in:
Mariusz Felisiak 2020-04-17 08:14:27 +02:00 committed by GitHub
parent 4c9886085b
commit eeab63e57e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -127,6 +127,7 @@ class BaseDatabaseCreation:
the serialize_db_to_string() method.
"""
data = StringIO(data)
table_names = set()
# Load data in a transaction to handle forward references and cycles.
with atomic(using=self.connection.alias):
# Disable constraint checks, because some databases (MySQL) doesn't
@ -134,9 +135,10 @@ class BaseDatabaseCreation:
with self.connection.constraint_checks_disabled():
for obj in serializers.deserialize('json', data, using=self.connection.alias):
obj.save()
table_names.add(obj.object.__class__._meta.db_table)
# Manually check for any invalid keys that might have been added,
# because constraint checks were disabled.
self.connection.check_constraints()
self.connection.check_constraints(table_names=table_names)
def _get_database_display_str(self, verbosity, database_name):
"""