如何使用test SQLITE3数据库而不是默认MySQL数据库测试DJANGO?
我在设置中的数据库。py
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dbname',
'USER': 'user',
'PASSWORD': 'password',
'HOST': 'mydb.com',
'TEST': { # it's not works
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}
但测试部分不起作用。
我使用此代码,它有效,但我不喜欢它。也许数据库中有其他方法描述了测试数据库?
if 'test' in sys.argv:
DATABASES['default'] = {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
My databases in settings.py
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dbname',
'USER': 'user',
'PASSWORD': 'password',
'HOST': 'mydb.com',
'TEST': { # it's not works
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}
But TEST section not work.
I use this code and it works but i don't like it. Maybe there are other way in databases section describe test database?
if 'test' in sys.argv:
DATABASES['default'] = {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个新文件your_app/test_settings.py
不要忘记使用新设置运行迁移
,最后,使用新的test_settings.py运行测试
create a new file your_app/test_settings.py
don't forget to run migrate using your new settings
then finally, run your tests with your new test_settings.py