在settings.py中指定Django测试数据库名称
我使用 python 对象指定数据库:
DATABASES = {
'default':{
'ENGINE':'mysql',
'NAME':'testsqldb',
'USER':'<username>',
'PASSWORD':'<password>',
},
'dynamic_data':{
'ENGINE': 'sqlite3',
'NAME':'',
'USER':'',
'PASSWORD':''
},
}
如何指定测试数据库的名称?我一直在尝试在 settings.py 文件中使用 TEST_NAME = 'auto_tests'
。但是,当我运行 python manage.py test
Creating test database 'default'...
Got an error creating the test database: (1007, "Can't create database 'test_testsqldb'; database exists")
Type 'yes' if you would like to try deleting the test database 'test_testsqldb', or 'no' to cancel:
我希望系统在运行测试时创建一个单独的数据库,大概称为“auto_tests_testsqldb”;但是,它仍然询问我有关 test_testsqldb 的信息。
任何建议表示赞赏!
I'm specifying the databases using a python object:
DATABASES = {
'default':{
'ENGINE':'mysql',
'NAME':'testsqldb',
'USER':'<username>',
'PASSWORD':'<password>',
},
'dynamic_data':{
'ENGINE': 'sqlite3',
'NAME':'',
'USER':'',
'PASSWORD':''
},
}
How can I specify the name of my test database? I've been trying to use TEST_NAME = 'auto_tests'
in the settings.py file. However, when I run python manage.py tests <app_name>
I get the following message:
Creating test database 'default'...
Got an error creating the test database: (1007, "Can't create database 'test_testsqldb'; database exists")
Type 'yes' if you would like to try deleting the test database 'test_testsqldb', or 'no' to cancel:
I'm expecting the system to create a separate database when running my tests, presumably called 'auto_tests_testsqldb'; however, it's still asking me about test_testsqldb.
Any advice is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Django 1.6 及更低版本中,
TEST_NAME
应该是数据库字典之一的键。但在 Django 1.7 及更高版本中,您使用TEST
键,它是测试数据库设置的字典。您可能想要:
或者,也许您想使用不同的引擎进行测试?在这种情况下,我认为您只需创建一个单独的设置文件进行测试。它可以从您的标准设置模块导入并覆盖
DATABASES
。In Django 1.6 and below,
TEST_NAME
should be a key of one of your database dictionaries. But in Django 1.7 and above, you use aTEST
key which is a dictionary of settings for test databases.You probably want:
Alternatively, perhaps you are wanting to use a different engine for your tests? In that case, I think you'll just have to create a separate settings file for testing. It can import from your standard settings module and override
DATABASES
.