New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL in some situations will generate spurious remove_constraint #251

Closed
sqlalchemy-bot opened this Issue Dec 4, 2014 · 5 comments

Comments

Projects
None yet
1 participant
@sqlalchemy-bot

sqlalchemy-bot commented Dec 4, 2014

Migrated issue, originally created by Johannes Erdfelt (@jerdfelt)

If a table includes a unique index with the same name as a column, the correct_for_autogen_constraints code for MySQL will remove it. This will cause the autogenerate code to generate a spurious remove_constraint.

The attached script reproduces the problem.

I have a patch and unit test that fixes the problem by ignoring unique indexes in correct_for_autogen_constraints since MySQL will never implicitly create a unique index.


Attachments: mysql_testcase.py

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Dec 4, 2014

Changes by Johannes Erdfelt (@jerdfelt):

  • changed title from "MySQL in some situations will generatespurious rem" to "MySQL in some situations will generate spurious re"
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Dec 4, 2014

Michael Bayer (@zzzeek) wrote:

MySQL: Ignore unique indexes when removing implicit indexes

MySQL will implicitly create indexes when using foreign keys. Alembic
attempts to remove those implicit indexes so they don't appear as
removes when comparing metadata.

However, unique indexes with the same name as a column are considered
as possibly implicitly created causing alembic to emit a spurious
'remove_constraint'.

Since MySQL will never implicitly create unique indexes, they can be
safely ignored when removing the implicit indexes.

Fixes #251

22667c1

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Dec 4, 2014

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Dec 4, 2014

Michael Bayer (@zzzeek) wrote:

see also c307d22

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Dec 4, 2014

Johannes Erdfelt (@jerdfelt) wrote:

Thanks for the quick merge.

FWIW, I ran into this because of this unique index in Nova:

https://github.com/openstack/nova/blob/master/nova/db/sqlalchemy/models.py#L158

The recent fixes to alembic have made the autogenerate functionality much better.

@sqlalchemy-bot sqlalchemy-bot added the bug label Nov 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment