test.utils.create_test_db cannot drop existing test database when using MySQL
|Reported by:||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
If the test database is not removed during the previous test run, then django will try to drop it and recreate it. With MySQL this yields:
Got an error recreating the test database: (1192, "Can't execute the given command because you have active locked tables or an active transaction")
I fixed this by closing the connection and creating a new one before the execution of the DROP command.
connection.close() from django.db import connection cursor = connection.cursor() cursor.execute("DROP DATABASE %s" % qn(TEST_DATABASE_NAME))
Doing this requires adding a "global connection" to the top of the create_test_db function.