我使用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/