dayday0calories / CITS5505-Group-Project

CITS5505 Group Project
MIT License
0 stars 0 forks source link

Bug fixed: Database migration "ValueError:Constraint must have a name" #12

Open lingering126 opened 1 month ago

lingering126 commented 1 month ago

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.

MomobamiKiraly commented 1 month ago

great job

dayday0calories commented 1 month ago

I encountered the same issue, thanks for letting us know