I encountered a bug when I migrated database. I need to add user_id column in login_history table, reference User.id and set as foreign key.
When I run flask db upgrade command, it keeps showing me "ValueError:Constraint must have a name".
Fixed: I opened version file, found this line: batch_op.create_foreign_key(None, 'user', ['user_id'], ['id']). This is automatically generated by Alembic, the None means there is no constraint. That's the bug!!
I added a name, like this: batch_op.create_foreign_key('fk_user_id', 'user', ['user_id'], ['id']). Bug fixed.
I encountered a bug when I migrated database. I need to add
user_id
column inlogin_history
table, referenceUser.id
and set as foreign key.When I run
flask db upgrade
command, it keeps showing me "ValueError:Constraint must have a name".Fixed: I opened version file, found this line:
batch_op.create_foreign_key(None, 'user', ['user_id'], ['id'])
. This is automatically generated byAlembic
, theNone
means there is no constraint. That's the bug!!I added a name, like this:
batch_op.create_foreign_key('fk_user_id', 'user', ['user_id'], ['id'])
. Bug fixed.