我在一个使用 alembic 管理数据库迁移的团队中工作。我最近拉了master,并尝试运行alembic upgrade heads
.我收到以下消息;
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
ERROR [alembic.util.messaging] Requested revision a04c53fd8c74 overlaps with other requested revisions 453d88f67d34
FAILED: Requested revision a04c53fd8c74 overlaps with other requested revisions 453d88f67d34
当我尝试运行
alembic downgrade -1
时,我收到了相同的消息.运行alembic history
打印这个;453d88f67d34 -> a04c53fd8c74 (label_1, label_2) (head), Create such and such tables.
2f15c778e709, 9NZSZX -> 453d88f67d34 (label_1, label_2) (mergepoint), empty message
b1861bb8b23f, b8aa3acdf260 -> 2f15c778e709 (label_1, label_2) (mergepoint), Merge heads b18 and b8a
(...many more old revisions)
在我看来,这就像一部完美的历史。
alembic heads
报告 a04c53fd8c74 (label_1, label_2) (head)
.唯一让我觉得奇怪的是我的 alembic 版本 db 有两个值;
my_postgres=# SELECT * FROM alembic_version;
version_num
--------------
a04c53fd8c74
453d88f67d34
(2 rows)
我可以从谷歌搜索异常中找到的唯一引用是 source code ,我宁愿不通读。
怎么会出现这种情况?我应该如何解决它? “重叠”是什么意思?
最佳答案
我通过删除数据库中的旧版本号来“修复”它;
my_postgres=# DELETE FROM alembic_version WHERE version_num = '453d88f67d34';
DELETE 1
my_postgres=# SELECT * FROM alembic_version;
version_num
--------------
a04c53fd8c74
(1 row)
我现在可以运行升级和降级。我的历史和头脑看起来都一样。但我仍然不知道它为什么会发生,或者是否有一些数据库状态被巧妙地弄乱了,所以如果有人有更好的答案,请发布!
关于alembic - 如何修复 alembic 的 "Requested revision overlaps with other requested revisions"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42424320/