In my django project I have a few database connections:
eg.
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": "awesome",
...
},
"other_1": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": "other_1",
"TEST": {"MIRROR": default}
...
},
"other_2": {
"ENGINE": "django.db.backends.mysql",
"NAME": "other_2",
"TEST": {"MIRROR": default}
}
}
Note:
- The
default
andother_1
both arepostgres
backends andother_2
ismysql
backend. - I added
"TEST": {"MIRROR": default}
to the extra database config in a bid to avoid those databases being created during test. See this link.
Problem:
When I run the test, it complains about Unknown database 'test_awesome'
, the stack trace shows it's from MYSQL backend:
Traceback (most recent call last):
File "/Users/jlin/virtualenvs/awesome-1SH6mAZ2/lib/python3.6/site-packages/django/test/testcases.py", line 1005, in setUpClass
if not connections_support_transactions():
File "/Users/jlin/virtualenvs/awesome-1SH6mAZ2/lib/python3.6/site-packages/django/test/testcases.py", line 970, in connections_support_transactions
...
File "/Users/jlin/virtualenvs/awesome-1SH6mAZ2/lib/python3.6/site-packages/MySQLdb/__init__.py", line 85, in Connect
return Connection(*args, **kwargs)
File "/Users/jlin/virtualenvs/awesome-1SH6mAZ2/lib/python3.6/site-packages/MySQLdb/connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (1049, "Unknown database 'test_awesome'")
If I comment out the other_2
connection, the test runs fine.