FastAPI学习-28 alembic数据迁移报错:Target database is not up to date 报错解决办法

前言

当表结构有变更,数据迁移时,出现报错:Target database is not up to date

遇到的问题

执行迁移命令

alembic revision --autogenerate -m "testv4"

出现如下报错

>alembic revision --autogenerate -m "testv4"
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版本与迁移脚本版本不一致导致的报错

解决办法

解决办法,找到testv4前面的版本号,如下红色圈出来部分

找到数据库里面alembic_version表,改成上面一样的版本号即可

之后再执行同步命令

(venv) D:\code\fast_project>alembic revision --autogenerate -m "testv4"
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.autogenerate.compare] Detected removed index 'ix_task_job_next_run_time' on 'task_job'
INFO  [alembic.autogenerate.compare] Detected removed table 'task_job'
INFO  [alembic.autogenerate.compare] Detected type change from TEXT() to LONGTEXT() on 'test_case.test_case'
Generating D:\code\fast_project\alembic\versions\1d6b74d931dd_testv4.py ...  done

(venv) D:\code\fast_project>alembic upgrade head
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade a7f87581d476 -> 1d6b74d931dd, testv4
posted @ 2024-01-15 21:02  上海-悠悠  阅读(421)  评论(0编辑  收藏  举报