flask-migrate doesn't work When I add models with ForeignKey

橙三吉。 提交于 2019-12-04 22:00:15

@knight We have migrated for many times.'user' table is in the database. But I found that if I code like

author_id = db.Column(db.Integer)

and migrate, It's nothing wrong. And than add the code like

author_id = db.Column(db.Integer, db.ForeignKey('user.id'))

and migrate again, It passed. It's strange. I don't know why exactly.

Our migrate code is

api.update_db_from_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, db.metadata)

From what I can see the user table is not being created (could not find table 'user' with which to generate a foreign key to target column 'id'). Try migrating the User first and, therefore, making the user table, and then doing the PubSquare.

EDIT: Have you tried reading the docs? http://sqlalchemy-migrate.readthedocs.org/en/v0.7.1/changeset.html#constraint seems to help.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!