Skip to content
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

correct_for_autogen_constraints tries to remove indexes twice for composite foreign keys #240

Closed
sqlalchemy-bot opened this issue Nov 2, 2014 · 5 comments

Comments

@sqlalchemy-bot
Copy link

@sqlalchemy-bot sqlalchemy-bot commented Nov 2, 2014

Migrated issue, originally created by Fayaz Khan (@fayaz)

Autogenerate script seems to be failing with:

  File "<string>", line 7, in run_migrations
  File "/home/fayaz/Programming/weaver-env/local/lib/python2.7/site-packages/alembic/environment.py", line 696, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/home/fayaz/Programming/weaver-env/local/lib/python2.7/site-packages/alembic/migration.py", line 248, in run_migrations
    self):
  File "/home/fayaz/Programming/weaver-env/local/lib/python2.7/site-packages/alembic/command.py", line 87, in retrieve_migrations
    autogen._produce_migration_diffs(context, template_args, imports)
  File "/home/fayaz/Programming/weaver-env/local/lib/python2.7/site-packages/alembic/autogenerate/api.py", line 140, in _produce_migration_diffs
    autogen_context, object_filters, include_schemas)
  File "/home/fayaz/Programming/weaver-env/local/lib/python2.7/site-packages/alembic/autogenerate/api.py", line 218, in _produce_net_changes
    inspector, metadata, diffs, autogen_context)
  File "/home/fayaz/Programming/weaver-env/local/lib/python2.7/site-packages/alembic/autogenerate/compare.py", line 100, in _compare_tables
    diffs, autogen_context, inspector)
  File "/home/fayaz/Programming/weaver-env/local/lib/python2.7/site-packages/alembic/autogenerate/compare.py", line 263, in _compare_indexes_and_uniques
    metadata_indexes)
  File "/home/fayaz/Programming/weaver-env/local/lib/python2.7/site-packages/alembic/ddl/mysql.py", line 92, in correct_for_autogen_constraints
    conn_indexes.remove(idx)
KeyError: Index('variant_value_association_value_key', Column('attribute', INTEGER(display_width=11), ForeignKey(u'variant_property_value.attribute'), table=<variant_value_association>, primary_key=True, nullable=False), Column('value', VARCHAR(length=64), ForeignKey(u'variant_property_value.value'), table=<variant_value_association>, nullable=False))

It fails here.
https://bitbucket.org/zzzeek/alembic/src/9650ccfb6841de45efdedb40de5b5f9d3d2f4582/alembic/ddl/mysql.py?at=master#cl-92

Table in question:

variant_value_association = Table(
    'variant_value_association', Base.metadata,
    Column('variant', ForeignKey('item_variant.id',
                                 name='variant_value_association_variant_key'),
           primary_key=True),
    Column('attribute', Integer, primary_key=True),
    Column('value', Unicode(64), nullable=False),
    ForeignKeyConstraint(
        ['attribute', 'value'],
        ['variant_property_value.attribute', 'variant_property_value.value'],
        name='variant_value_association_value_key'))

I think correct_for_autogen_constraints seems to be removing idx more than once for cols with the same col.foreign_keys.

@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Nov 2, 2014

Michael Bayer (@zzzeek) wrote:

hi i need the target backend here please, that is critical

@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Nov 2, 2014

Michael Bayer (@zzzeek) wrote:

mysql, OK

@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Nov 2, 2014

Michael Bayer (@zzzeek) wrote:

  • Repaired issue related to the fix for #208 and others; a composite
    foreign key reported by MySQL would cause a KeyError as Alembic
    attempted to remove MySQL's implicitly generated indexes from the
    autogenerate list.
    fixes #240

b16bdf8

@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Nov 2, 2014

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Nov 2, 2014

Michael Bayer (@zzzeek) wrote:

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.