I have several views defined in alembic migration script, and so I defined op.execute('drop view xxx') to drop all of my view sql files. When I ran script 'alembic downgrade -1' to drop all of the tables, views, indexes, MySQL, SQLITE3 worked fine. When working with Postgresql, I got below:
qlalchemy.exc.InternalError: (InternalError) cannot drop table tbl_1 because other objects depend on it
DETAIL: view view_1 depends on table tbl_1
HINT: Use DROP ... CASCADE to drop the dependent objects too.
'\nDROP TABLE tbl_1' {}
Does sqlalchemy/alembic support 'drop table xxx cascade' for most databases?
Thanks,
Postgresql works fine with both 'alembic revision --autogenerate' and 'alembic upgrade head' commands, but failed with 'alembic downgrade -1' command, giving error:
sqlalchemy.exc.InternalError: (InternalError) cannot drop view view_1 because other objects depend on it
DETAIL: view view_2 depends on view view_1
HINT: Use DROP ... CASCADE to drop the dependent objects too.
'drop view view_1{}
When I removed all of op.execute('drop view xxx') and op.execute('create view xxx as ...') scripts, all of commands work fine even in Postgresql. I think this is because I have put clear relationship in table class in my schema module:
class Mytable(Base):
__tablename__ = 'tbl_mytable
id = Column(String(15), primary_key = True)
name = Column(String(25))
...
children = relationship('Yourtable')
but for view sql statement, I can just use pure sql code op.execute('...') to do both 'create' and 'drop' view work, no relationship involved. Surely it is true that we don't deal with any relationship between view and view, or between view and table in all of the database systems which should be very complicated.
qlalchemy.exc.InternalError: (InternalError) cannot drop table tbl_1 because other objects depend on it
DETAIL: view view_1 depends on table tbl_1
HINT: Use DROP ... CASCADE to drop the dependent objects too.
'\nDROP TABLE tbl_1' {}