《flask web 开发》地第十一章做Flask-Migrate数据库迁移时,遇到了Target database is not up to date报错。
按照书上在模型models.py中增加了一个类Post,并且更新了User类。
表增加字段,实现对表结构的更改, 所以这时候会用到Flask-Migrate来创建数据库迁移脚本(执行 python manage.py db migrate),文件夹migrations\versions会有相应的变化,跟着执行 python manage.py db upgrade 把迁移应用到数据库中,更新数据,且不影响其中保存的数据。一切都如期进行。
后来我发现 模型models.py中表Post的字段avatar_hash拼写错了(写成 avatar_user),所以我在Post表中改正过来,再执行 python manage.py db migrate就报错了 Target database is not up to date。
删除 migrations文件夹再 执行 python manage.py db init,之后再 执行 python manage.py db migrate还是一样报错。
gegoole查到在stackoverflow有人曾经提问过:
Alembic stores the db version in a table it creates called alembic_version. This table contains a single field and row alembic_version.version_num. Make sure the value for this matches the filename of the most recent file in migrations/version. This version number