python - flask-migrate:无法升级数据库,因为 "table does not exist"

标签 python postgresql sqlalchemy flask-sqlalchemy flask-migrate

我正在使用带有 postgres 数据库的 sqlalchemy 开发一个 flask 应用程序。我正在使用 flask-migrate 迁移我的数据库。 我不得不更改数据库中我的一个表的名称,并且在尝试迁移 (flask-migrate) 时出现错误

sqlalchemy.exc.InternalError: (psycopg2.InternalError) cannot drop table category_announcement_date because other objects depend on it
DETAIL:  constraint announcement_dates_id_fkey on table announcement_dates depends on table category_announcement_date
HINT:  Use DROP ... CASCADE to drop the dependent objects too.
[SQL: '\nDROP TABLE category_announcement_date']

我不知道如何将这个问题告诉 flask-migrate,所以我想到了手动执行此操作的好主意,所以我转到 psql 并按照错误消息的建议将表与 CASCADE 命令一起删除。一切正常,但现在我无法完成迁移?运行升级时我得到

python manage.py db upgrade
...
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) table "category_announcement_date" does not exist

这可能是因为我只是手动删除了表格? 有谁知道我怎样才能摆脱这个烂摊子? 谢谢卡尔

最佳答案

好的,我注意到删除版本文件并重复迁移就可以了 干杯 fl

关于python - flask-migrate:无法升级数据库,因为 "table does not exist",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36373897/

相关文章:

python - S3 使用 boto 和 SigV4 - 缺少主机参数

python - 如何在python中为套接字设置发送缓冲区大小

python - 有没有办法在 SQLAlchemy 连接字符串中指定 Postgres 模式?

java - 将 SQL/plPGsql 测试移植到 Java/JDBC : test an exception

python-3.x - SqlAlchemy/Python 正确捕获 psycopg2.errors.UndefinedTable

python - 使用 SQLalchemy 从表中获取用户列表

python - Pandas:添加新的计算(分数)行

python - 如何在 Matplotlib 图中单独标记条形?

node.js - 如何回滚一天?

java - 异常后保留jdbc批处理语句