cha*_*isz 5 postgresql alembic
如果我尝试删除不存在的约束:在修订文件中
op.drop_constraint('exists_in_some_db_fkey', 'table', type='foreignkey')
Run Code Online (Sandbox Code Playgroud)
我有:
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedObject)
constraint "exists_in_some_db_fkey" of relation "table" does not exist
[SQL: 'ALTER TABLE extensions DROP CONSTRAINT exists_in_some_db_fkey']
(Background on this error at: http://sqlalche.me/e/f405)
Run Code Online (Sandbox Code Playgroud)
这是我们的错,我们有一些损坏的数据库,但如果我们可以删除约束检查 IF EXISTS,它可以解决我们的问题。
我们最近无法更改我们的模型。
使用 Alembic,您始终可以选择手动执行 SQL 语句,如下所示:
op.execute("ALTER TABLE new DROP CONSTRAINT IF EXISTS parent_id_f")
Run Code Online (Sandbox Code Playgroud)