alembic
alembic copied to clipboard
take topological ordering into account when adding/dropping dependent cols/tables
Migrated issue, originally created by lu_zero NA
Example:
roles = db.Table('roles',
db.Column('customer_id', db.Integer, db.ForeignKey('customer.id')),
db.Column('company_id', db.Integer, db.ForeignKey('company.id')),
# db.Column('role_id', db.Integer, db.ForeignKey('role.id'))
)
"""
class Role(db.Model):
id = db.Column(db.Integer, primary_key = True)
name = db.Column(db.String(64), index = True, unique = True)
description = db.Column(db.String(256), index = True, unique = True)
customer = db.relationship("Customer", uselist=False, secondary=roles, backref="role")
"""
INFO [alembic.autogenerate] Detected removed table u'role' INFO [alembic.autogenerate] Detected removed column 'roles.role_id'
sqlalchemy.exc.InternalError: (InternalError) cannot drop table role because other objects depend on it DETAIL: constraint roles_role_id_fkey on table roles depends on table role
Inverting the order of the operation did the right thing.
Michael Bayer (@zzzeek) wrote:
OK well the column remove isn't even needed really, you're dropping the table..
Michael Bayer (@zzzeek) wrote:
so anyway, yeah, table adds/drops column adds/drops don't separately take dependency sorting into account. this might require a breaking up of how these different diffs are generated because adds go in one direction while drops go in another, and it can get pretty complicated. you'll have to manually edit your file for now in this case.
Changes by lu_zero NA:
- edited description
Changes by Michael Bayer (@zzzeek):
- changed title from "Wrong drop order on coumn/table removal" to "take topological ordering into account when adding"