python MySQLdb.ProgrammingError:(1146,“表' '不存在”)

eivgtgni  于 2023-05-16  发布在  Python
关注(0)|答案(2)|浏览(250)

我得到错误“MySQLdb.ProgrammingError:(1146,“Table 'test_sageservice.processed_transactions' doesn't exist”)”当我尝试使用命令pyton manage.py test运行我的测试时。
我试过运行python manage.py makemigrationspython 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',
   }
}
4nkexdtk

4nkexdtk1#

测试数据库需要与生产数据库不同。一旦测试用例运行,测试数据库就会被销毁。在您的情况下,数据库未创建。您应该阅读此文档以了解详细信息https://docs.djangoproject.com/en/4.2/topics/testing/overview/
另外,请确保您已将包含Dashboard模型的应用程序添加到INSTALLED_APPS设置中。

bksxznpy

bksxznpy2#

听起来您的测试数据库迁移可能处于停滞状态。运行python manage.py test时考虑销毁数据库。

相关问题