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.

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值