本文介绍了python manage.py migration --fake< appname>vs python manage.py migration --fake< appname>零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行 python manage.py migration --fake photos zero 时:

运行上述命令后,我在该错误发生时运行了 python manage.py migration .

After running above command, I ran python manage.py migrate at that time this error occurred.

文件"C:\ Users ... \ lib \ site-packages \ django \ db \ backends \ sqlite3 \ base.py",执行中的第411行返回Database.Cursor.execute(自己,查询)

File"C:\Users...\lib\site-packages\django\db\backends\sqlite3\base.py",line 411, in executereturn Database.Cursor.execute(self, query)

当我运行 python manage.py migration --fake photos :

运行上述命令后,我运行了 python manage.py migration ,并且运行良好.

After running above command, I ran python manage.py migrate and this work perfectly.

Running migrations:
  Applying photos.0003_auto_20210303_0123... OK

所以我的问题是 python manage.py migration --fake< appname> python manage.py migration --fake< appname>和之间有什么区别?零,为什么第一个命令会向我抛出错误?

So my question is that what difference between python manage.py migrate --fake <appname> vs python manage.py migrate --fake <appname> zero and Why first command throws me an error?

谢谢..

推荐答案

您似乎对-fake 标志有误解.根据文档 -假标志:

You appear to have a misunderstanding about the --fake flag. According to the documentation the --fake flag:

它还进一步指出,它是供高级用户手动进行更改的.基本上,Django创建一个表 django_migrations 来管理您的迁移.它将添加一个条目以标记是否已应用迁移.-fake 的作用只是根据您指定的迁移在此表中添加条目/从该表中删除条目.同样, zero 表示撤消所有迁移.

It also further states that it is meant for advanced users if they are making changes manually. Basically Django makes a table django_migrations to manage your migrations. It adds an entry to it to mark if a migration has been applied. What --fake does is simply add / remove the entries to / from this table according to the migration you specify. Also the zero means to undo all migrations.

python manage.py migrate --fake photos zero

上面的命令意味着您基本上是对Django说:

The above command means you basically say to Django:

python manage.py migrate --fake <appname>

在上面的命令中,您没有指定迁移(在先前,您指定为零),这意味着假设您的意思是直到最近的迁移.基本上使用-fake ,此命令的意思是:

In the above command you don't specify the migration (in previous you specified zero), this means to assume that you mean till the most recent migration. Basically with --fake this command means:

据我了解,您仅作了一些更改,并想更新数据库,为此,您可以简单地编写:

From my understanding you only made some changes and wanted to update your database, for this you could have simply written:

python manage.py migrate

这篇关于python manage.py migration --fake&lt; appname&gt;vs python manage.py migration --fake&lt; appname&gt;零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 10:00