我得到错误“MySQLdb.ProgrammingError:(1146,“Table 'test_sageservice.processed_transactions' doesn't exist”)”当我尝试使用命令pyton manage.py test
运行我的测试时。
我试过运行python manage.py makemigrations
和python manage.py migrate
,一切正常,但当我试着运行我的测试时,我得到了下面的错误
我的tests.py看起来像这样
from django.test import TestCase
# Create your tests here.
class DashboardTests(TestCase):
def test_uses_dashboard_template(self):
response = self.client.get('/')
self.assertTemplateUsed(response, 'dashboard.html')
我的设置如下所示
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'sageservice',
'USER': 'root',
'PASSWORD': 'not_my_password',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
2条答案
按热度按时间4nkexdtk1#
测试数据库需要与生产数据库不同。一旦测试用例运行,测试数据库就会被销毁。在您的情况下,数据库未创建。您应该阅读此文档以了解详细信息https://docs.djangoproject.com/en/4.2/topics/testing/overview/
另外,请确保您已将包含
Dashboard
模型的应用程序添加到INSTALLED_APPS设置中。bksxznpy2#
听起来您的测试数据库迁移可能处于停滞状态。运行
python manage.py test
时考虑销毁数据库。