Skip to content

Commit 0106ad1

Browse files
committed
make DatabaseCreation._destroy_test_db() clear the test database
1 parent 0b6ec2e commit 0106ad1

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

django_mongodb/creation.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from django.conf import settings
12
from django.db.backends.base.creation import BaseDatabaseCreation
23

34

@@ -7,6 +8,11 @@ def _execute_create_test_db(self, cursor, parameters, keepdb=False):
78
self._destroy_test_db(parameters["dbname"], verbosity=0)
89

910
def _destroy_test_db(self, test_database_name, verbosity):
11+
# At this point, settings still points to the non-test database. For
12+
# MongoDB, it must use the test database.
13+
settings.DATABASES[self.connection.alias]["NAME"] = test_database_name
14+
self.connection.settings_dict["NAME"] = test_database_name
15+
1016
for collection in self.connection.introspection.table_names():
1117
if not collection.startswith("system."):
1218
self.connection.database.drop_collection(collection)

0 commit comments

Comments
 (0)