【发布时间】:2018-04-20 08:04:01
【问题描述】:
我使用 inspectdb 从与 MySQL Connector/Python 连接的 MySQL 数据库中导入 Models 架构。
当我运行测试时,系统显示:
django.db.utils.ProgrammingError: Table 'test_mydb.cards' doesn't exist
但是表名只是mydb.cards,而不是test_mydb.cards
为什么要添加这个前缀?我的应用名称只是container。
【问题讨论】:
-
当您运行
manage.py test时,它会创建一个全新的数据库(通过在数据库名称前添加test_)以确保测试不会与您的真实数据混淆。但这并不能解释为什么 Django 没有创建正确的表。 -
有没有办法强制 Django 使用同一个数据库?我已在 MySQL Workbench 中将整个架构设置为只读
标签: python mysql django pycharm mysql-connector-python