Applying DATABASE_OPTIONS when testing Django project (or make it to use InnoDB for MySQL)
-
21-08-2019 - |
Question
As the title says, I want to apply DATABASE_OPTIONS settings when I run my tests via ./manage.py test
. In django/db/backends/creation.py
, it does not consider this option at all in both create_test_db()
and _create_test_db()
.
This breaks a test with a view that uses transaction.rollback
function with InnoDB. It seems that test databases are not created with InnoDB storage engine.
Is there any workaround or fix to this problem?
Solution 2
I've found the reason by myself. I have to use TransactionTestCase instead of normal TestCase base class. See the documentation.
OTHER TIPS
One workaround might be to set the default storage engine on your server to InnoDB.
in my.cnf:
set default_storage_engine=InnoDB
That should work unless django is explicitly picking MyISAM.