【发布时间】:2021-07-07 14:45:16
【问题描述】:
我正在为遇到此问题的任何人自行记录db.create_all 的解决方案。希望它会对某人有所帮助。
以下是对我没有帮助的其他线程列表:
- db.create_all() doesn't create tables defined in separate file
- Flask SQLAlchemy db.create_all() not creating database
- Flask-SQLAlchemy create_all doesn't work
- Flask_SQLAlchemy create_all() doesn't work
我尝试在 pytest 的 conftest.py 中创建和销毁 db。 Alembic autogenerate 对我有用,但由于某种原因 db.create_all 不是。在db.create_all 之前导入模型什么也没做。在我的__init__.py 中也没有在db = SQLAlchemy() 之后导入模型(我使用的是应用程序工厂模式)。我也在使用声明式基础,这可能是问题的一部分。
每次运行 pytest 都会导致以下错误:
ERROR tests/test_main.py::test_index - sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) relation "rule" does not exist
【问题讨论】:
标签: python flask sqlalchemy pytest flask-sqlalchemy