take topological ordering into account when adding/dropping dependent cols/tables

Issue #146 new
lu_zero NA
created an issue


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.

Comments (5)

  1. Michael Bayer repo owner

    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.

  2. Log in to comment