A "cascade" feature requires reading the database. For Alembic, reading the database occurs in the "autogenerate" feature, which will render the "drop_table()" instructions in the correct order in your migration script.
if not using autogenerate, the reading has to be done elsewhere. This is a long-supported feature in SQLAlchemy but is not usually as applicable to Alembic, as Alembic is trying to get you to create migrations that work without reading the database. The "drop tables in the correct order" feature requires that the foreign key relationships be known between the tables. If not using autogenerate and not specifying the order directly, you can let SQLAlchemy "reflect" those details from the database. But these approaches won't work in --sql mode. A migration script such as this will do it: m = MetaData() t1 = Table('table1', m, Column('id', Integer, primary_key=True)) t2 = Table('table2', m, Column('id', Integer, primary_key=True), Column('table1id', Integer, ForeignKey('t1.id'))) m.drop_all(op.get_bind(), checkfirst=False) Or this: m = MetaData() t1 = Table('table1', m, autoload=True, autoload_with=op.get_bind()) t2 = Table('table2', m, autoload=True, autoload_with=op.get_bind()) m.drop_all(op.get_bind(), checkfirst=False) the above two scripts require live DB access and also are more verbose, but that approach is an option if you don't want to manually sort the DROP commands. On Nov 1, 2012, at 9:54 AM, junepeach wrote: > Thanks for the suggestion.I solved the problem by putting the dependents' > drop command first in function def downgrade(): > For example, if A refers to/uses B, I need to drop B first, then drop A. I > don't know other better way. Will Alembic support 'cascade' in future > version? > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/sqlalchemy/-/WwmZXJN_oXEJ. > To post to this group, send email to sqlalchemy@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.