'One test database is not created when two database are used
I have two databases to use in django project.
in settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
"NAME": "mydb",
"USER": "root",
"PASSWORD": config("DB_PASSWORD"),
"HOST": "127.0.0.1"
"PORT": 3306,
'OPTIONS': {
'charset': 'utf8mb4',
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
},
'TEST': {
'NAME': 'test_mydb',
'MIRROR': "default",
},
},
'extern': {
'ENGINE': 'django.db.backends.mysql',
'NAME': "mydb_extern",
'USER': "root",
'PASSWORD': config("DB_EXTERN_PASSWORD"),
'HOST': "127.0.0.1",
'PORT': 3306,
},
'TEST': {
'NAME': 'test_mydb_extern',
'MIRROR': "default",
},
}
extern has the table 'MyInfo'
in extern_app/test.py
from django.test import TestCase
from extern_db.models import MyInfo
class HelpViewTest(TestCase):
databases = {"default", "extern"}
def test_model_script(self):
items = MyInfo.objetcts.all()
for cnt,i in enumerate(items):
print(cnt)
There comes error like this.
django.db.utils.ProgrammingError: (1146, "Table 'default.myinfo' doesn't exist")
extern has the myinfo table, however somehow application try to search myinfo from default.
Why it happens?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
