sqlalchemy / sqlalchemy/alembic
take topological ordering into account when adding/dropping dependent cols/tables
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 375
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Alembic autogenerate's handling of detected removed tables and columns, using the roles and role example to reproduce the failure. Trace the generated operation order and verify that dependent constraints or columns are handled before their referenced tables are dropped.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, sqlalchemy
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100