Skip to content

change to no longer sort index cols for index sig produces false positives on mysql #1240

@provinzio

Description

@provinzio

Describe the bug
Although my database with unique constraints across multiple columns matches my table model exactly, alembic generates drop_index/drop_constraint commands.

Expected behavior
alembic revision --autogenerate shouldn't generate any code

To Reproduce

# This is an example table of mine with a unique constraint across multiple columns
class DisturbanceRecorder(Base):
    __tablename__ = 'disturbance_recorders'
    __table_args__ = (sa.UniqueConstraint("device_name", "contact_id"),)

    id = sa.Column(sa.Integer, primary_key=True)
    device_name = sa.Column(sa.String(255), nullable=False)
    contact_id = sa.Column(sa.ForeignKey('contacts.id', ondelete='RESTRICT'), index=True, nullable=False)
    contact = sa.orm.relationship("Contact")

# my database has everything setup according to the table model, but
# alembic revision --autogenerate generates following code
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('device_name', 'disturbance_recorders', type_='unique')
    op.drop_index('device_name', table_name='disturbance_recorders')
    # ### end Alembic commands ###

Versions.

  • OS: Windows 10 Pro 22H2
  • Python: 3.9.1
  • Alembic: >= 1.10.0
  • SQLAlchemy: 1.3.23
  • Database: MySQL 5.5.46
  • DBAPI:

Additional context
I recently updated from alembic==1.5.4 to the latest release 1.10.4 and observed the bug. I tested all versions and realized, that all version >= 1.10.0 do not work for me. I downgraded to alembic==1.9.4 which does not show any misbehavior.

Have a nice day!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions