当我运行python manage.py test
时,django每次都会问一个奇怪的问题:
$ python manage.py test
Creating test database for alias 'default'...
Got an error creating the test database: (1044, "Access denied for user 'nyble'@'localhost' to database 'test_nybledb'")
Type 'yes' if you would like to try deleting the test database 'test_nybledb', or 'no' to cancel:
我原以为它只是删除并重新制作一个基本的sqlite3数据库,我不想要这种行为。
我是说是或否它只是退出测试:
Destroying old test database for alias 'default'...
Got an error recreating the test database: (1044, "Access denied for user 'nyble'@'localhost' to database 'test_nybledb'")
在我有
的设置中DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'nybledb',
'USER': 'nyble',
'PASSWORD': 'password',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}
如何在运行测试期间停止此操作并使其使用正常的sqlite3 db?
答案 0 :(得分:4)
您可以在settings.py中进行设置。它说如果在命令行输入中有'test',请使用sqlite作为db engine。
import sys
if 'test' in sys.argv or 'test_coverage' in sys.argv: #Covers regular testing and django-coverage
DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3'