簡體   English   中英

創建測試數據庫時出錯:Django unittest

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM