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

Foreign key creation fails if table has already a foreign key to referenced table #254

Closed
sqlalchemy-bot opened this Issue Dec 13, 2014 · 2 comments

Comments

Projects
None yet
2 participants
@sqlalchemy-bot

sqlalchemy-bot commented Dec 13, 2014

Migrated issue, originally created by Lucas Kahlert (@f3anor)

If you create add a column incl. a foreign key with a batch operation, e.g.

with op.batch_alter_table('quest') as batch_op:
    batch_op.add_column(sa.Column('therapist_id', sa.String(255), nullable=True))
    batch_op.create_foreign_key('fk_quest_therapist_id_user', 'user', ['therapist_id'], ['username'])

but the referenced table (user) was already created, because there is another column in quest referring to user, the upgrade command will produce the follwing error:

InvalidRequestError: Table 'user' is already defined for this MetaData instance.  Specify 'extend_existing=True' to redefine options and columns on an existing Table object.
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Dec 13, 2014

Michael Bayer (@zzzeek) wrote:

  • Fixed bug in batch where if the target table contained multiple
    foreign keys to the same target table, the batch mechanics would
    fail with a "table already exists" error. Thanks for the help
    on this from Lucas Kahlert. fixes #254

b20ad56

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Dec 13, 2014

Changes by Michael Bayer (@zzzeek):

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