【问题标题】:Why is Alembic running the wrong migration script?为什么 Alembic 运行错误的迁移脚本?
【发布时间】:2015-10-08 04:13:13
【问题描述】:

当我尝试时

alembic upgrade head

Alembic 运行之前的迁移脚本,显然由于我的架构已更改而引发错误。

在我的数据库中,我将version_num 设置为48957fdfe8d5。运行后

alembic revision -m '<my message>'

Alembic 创建了新的脚本文件——我想运行的那个——在顶部

revision = '28cc06993b73'
down_revision = '4d5f9ba76c5e'

换句话说,一切看起来都很好。那么为什么它明显是在4d5f9ba76c5e而不是28cc06993b73中运行代码呢?我也试过了

alembic upgrade 28cc06993b73

但它仍然运行4d5f9ba76c5e 中的代码。这是日志:

$ alembic upgrade 28cc06993b73
INFO  [alembic.migration] Context impl MySQLImpl.
INFO  [alembic.migration] Will assume non-transactional DDL.
Starting in DEBUG mode
INFO  [alembic.migration] Running upgrade 48957fdfe8d5 -> 4d5f9ba76c5e, Breaking up metadata into required and optional

另外,如果我查看 Alembic 的历史记录,我会发现那个头像在 28cc06993b73

$ alembic history
Starting in DEBUG mode
4d5f9ba76c5e -> 28cc06993b73 (head), creating soft file table
48957fdfe8d5 -> 4d5f9ba76c5e, Breaking up metadata into required and optional
<base> -> 48957fdfe8d5, Init

提前致谢。

【问题讨论】:

    标签: alembic


    【解决方案1】:

    首先你说你在数据库中的版本号是 48957fdfe8d5,所以根据你的 alembic 历史,预计从 48957fdfe8d5 升级到 4d5f9ba76c5e。

    您还说“Alembic 运行之前的迁移脚本,显然会引发错误,因为我的架构已更改。”它显示什么错误?您是否手动更改了数据库以反映 28cc06993b73 中应该发生的情况?如果是这种情况,那么您可以运行

    alembic stamp head
    

    让您的数据库与 alembic 迁移同步

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-25
      • 2013-10-06
      • 2023-03-20
      • 2014-04-01
      • 2020-08-17
      • 1970-01-01
      • 1970-01-01
      • 2013-07-04
      相关资源
      最近更新 更多