flask_migrate 报错 Target database is not up to date

报错现象
(venv) [root@192 back-end]# flask db migrate -m "user add tokens"
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
ERROR [root] Error: Target database is not up to date.
报错原因:

flask_migrate 每次在执行数据库迁移操作时都会生成一个版本号,并且在数据库当中会生成一个管理版本的数据表alembic_version ,每次执行迁移操作,版本号都会写在这个表里面
出现上面的错误是由于在数据表里面找不到上一次的版本号导致的

解决方式:

方式一
直接删除migrate目录下面的versions 当中的版本记录文件,然后再执行迁移操作

方式二
在数据库当中补上版本号,再执行迁移操作

引用在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 is also contained inside the revision file in the revision variable that generally shows up on line 26 of the file. Make sure it matches the db version.
Another option is to simply drop the db and recreate it using alembic. If this is a development environment, where the data is not important, that would be my recommendation.

你可能感兴趣的:(flask)