python - 运行测试 Django Pycharm 时使用了错误的表

标签 python mysql django pycharm mysql-connector-python

我使用inspectdb从与MySQL Connector/Python连接的MySQL数据库导入模型架构。

当我运行测试时,系统显示:

django.db.utils.ProgrammingError: Table 'test_mydb.cards' doesn't exist

但是表名只是mydb.cards,而不是test_mydb.cards

为什么要添加这个前缀?我的应用程序的名称只是container

最佳答案

Django 使用 unittest用于测试的模块,它还创建一个用于测试的空白数据库,因为理想情况下测试应该始终在相同的空白数据库或固定装置填充的数据库上运行。

Tests that require a database (namely, model tests) will not use your “real” (production) database. Separate, blank databases are created for the tests.

Regardless of whether the tests pass or fail, the test databases are destroyed when all the tests have been executed.

检查是否对测试尝试访问的表进行了迁移排序,因为如果没有猴子补丁或解决方法,测试套件将无法访问所有没有迁移的表

关于python - 运行测试 Django Pycharm 时使用了错误的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47166085/

相关文章:

mysql - 当值不存在于两列中时选择

jquery - 使用ajax删除Django db中的记录

python - 如果第一个字符不是字母,则将字符串中的第一个字母大写?

python - 两个 IoT 应用程序能否同时访问一个蜂窝调制解调器,这样我就不必杀死 ModemManager 并失去我的互联网连接?

mysql - 获取某个项目的最新条目? mysql

python - 从磁盘中删除外键上的图像

django - DRF Browsable API 仅显示一台路由器

python - 在python中缓存数据库数据

python - 使用 python 时的警告信息

javascript - 在 Openshift 上使用 Angular 和 PHP 时出现跨域脚本错误