关于django:Django-单元测试报错没有创建数据表

9次阅读

共计 1431 个字符,预计需要花费 4 分钟才能阅读完成。

报错形容

报错如下

> python manage.py test tweets
..............
  File "C:\Users\17293\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\17293\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\Users\17293\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\17293\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\mysql\base.py", line 73, in execute
    return self.cursor.execute(query, args)
  File "C:\Users\17293\AppData\Local\Programs\Python\Python39\lib\site-packages\MySQLdb\cursors.py", line 206, in execute
    res = self._query(query)
  File "C:\Users\17293\AppData\Local\Programs\Python\Python39\lib\site-packages\MySQLdb\cursors.py", line 319, in _query
    db.query(q)
  File "C:\Users\17293\AppData\Local\Programs\Python\Python39\lib\site-packages\MySQLdb\connections.py", line 259, in query
    _mysql.connection.query(self, query)
django.db.utils.ProgrammingError: (1146, "Table'test_d_twitter_db.tweets_tweet'doesn't exist")
PS C:\Users\17293\Desktop\Coder\Python\Django\twitter> python .\manage.py makemigrations

数据表是单元测试本人创立的,是不是手动创立的
所以这个报错一开始让我摸不着头脑

解决方案

执行如下命令

python manage.py makemigrations

在执行单元测试的命令就好了

python manage.py test tweets

不须要执行

python manage.py migratie
正文完
 0