util命令错误找不到标识符

util命令错误找不到标识符

本文介绍了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命令错误找不到标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 08:24