Closed
Description
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.