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

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
Labels
batch migrations bug Something isn't working

Comments

@sqlalchemy-bot
Copy link

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
Copy link
Author

Michael Bayer (@zzzeek) wrote:

b20ad56

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

@sqlalchemy-bot sqlalchemy-bot added the bug Something isn't working label Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
batch migrations bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants