Alembic util命令错误找不到标识符

编程入门 行业动态 更新时间:2024-10-23 23:32:20
本文介绍了Alembic util命令错误找不到标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用Alembic处理项目中的本地迁移。它是第一次工作,但是随后我需要删除该文件夹并重新启动。(不要问为什么,我只需要这样做)我正在关注本教程,然后运行命令

I'm trying to use alembic to handle local migrations on my project. It worked the first time, but then I needed to delete the folder and restart.(don't ask why, I just had to) I'm following this tutorial and I run the command

python manage.py db init

没关系。但是当我尝试运行

And it was ok. But when I try to run

python manage.py db migrate

我遇到此错误:

alembic.util.CommandError: Can't locate revision identified by '31b8ab83c7d'

现在,看来Alembic正在寻找不再存在的修订。无论如何,有让Alembic忘记那个文件吗?还是像将比较从无重新启动到->重新自动生成一样?

Now, it seems that alembic is looking for a revision that doesn't exists anymore. There is anyway to make alembic forget that file? Or like restart the comparison from None to -> auto-generated again?

推荐答案

Alembic将版本历史记录存储在数据库中。因此,它使用存储在数据库中的值来搜索修订。我的个人数据库的版本号存储在表 alembic_version 中:

Alembic stores the version history in your database. Hence it is using the value stored in your database to search for the revision. The version number for my personal database is stored in the table alembic_version:

mysql> SELECT * FROM alembic_version; +-------------+ | version_num | +-------------+ | c8ad125e063 | +-------------+ 1 row in set (0.00 sec)

提示:如果它是基于SQL的数据库来查看表,请使用命令 SHOW TABLES 。

Hint: Use the command SHOW TABLES if it's a SQL based database to see the tables.

要解决您的问题,只需使用以下命令:

To solve your problem simply use the command:

DROP TABLE alembic_version;

或者与数据库版本表的名称无关。 然后,您需要使用以下命令重新初始化迁移文件夹:

Or whatever the name of database version table is. And then you need to re-init the migration folder using the command:

python manage.py db init

然后创建新迁移:

python manage.py db migrate

然后您应该很好在alembic中进行工作迁移。

And then you should be good to go with working migrations in alembic.

更多推荐

Alembic util命令错误找不到标识符

本文发布于:2023-10-07 15:28:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469776.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标识符   找不到   命令   错误   Alembic

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!