当我跑步时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?
您可以在settings.py中进行设置。它说如果命令行输入中有“ test”,则使用sqlite作为数据库引擎。
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'
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句