alembic icon indicating copy to clipboard operation
alembic copied to clipboard

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

Open sqlalchemy-bot opened this issue 11 years ago • 5 comments

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.

sqlalchemy-bot avatar Oct 08 '13 02:10 sqlalchemy-bot

Michael Bayer (@zzzeek) wrote:

OK well the column remove isn't even needed really, you're dropping the table..

sqlalchemy-bot avatar Oct 08 '13 13:10 sqlalchemy-bot

Michael Bayer (@zzzeek) wrote:

oh, different table, never mind.

sqlalchemy-bot avatar Oct 08 '13 13:10 sqlalchemy-bot

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.

sqlalchemy-bot avatar Oct 08 '13 14:10 sqlalchemy-bot

Changes by lu_zero NA:

  • edited description

sqlalchemy-bot avatar Oct 08 '13 02:10 sqlalchemy-bot

Changes by Michael Bayer (@zzzeek):

  • changed title from "Wrong drop order on coumn/table removal" to "take topological ordering into account when adding"

sqlalchemy-bot avatar Oct 08 '13 14:10 sqlalchemy-bot