fastapi:alembic提示Target database is not up to date.
一,报错信息:
ERROR [alembic.util.messaging] Target database is not up to date.
FAILED: Target database is not up to date.
二,原因
手动同步状态:你手动修改了数据库结构,使其已经与最新的模型一致,此时不需要运行 upgrade,只需要让 Alembic 以为它已经升级到了最新版。
修复版本冲突:当开发分支合并导致数据库的 alembic_version 表中的版本号与代码中的脚本对不上时,可以用它强行将数据库锚定到某个特定的版本。
三,解决:
执行:
alembic stamp head
相当于flask的 flask db stamp head
例子:
$ alembic revision --autogenerate -m "modify role8"
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
ERROR [alembic.util.messaging] Target database is not up to date.
FAILED: Target database is not up to date.
$ alembic stamp head
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.runtime.migration] Running stamp_revision d71cad7469bb -> c0d989709fb1
浙公网安备 33010602011771号