![](/img/trans.png)
[英]django test app error - Got an error creating the test database: permission denied to create database
[英]Got an error creating the test database: Django unittest
当我运行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 DB,所以我不希望这种行为。
无论我说是还是否,它都会退出测试:
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'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.