python manage.py migration --fake< appname>vs python manage.py migration --fake< appname>零 [英] python manage.py migrate --fake <appname> vs python manage.py migrate --fake <appname> zero

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

问题描述

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

要执行的操作:
取消应用所有迁移:照片运行迁移:呈现模型状态...完成
取消申请photos.0001_initial ... FAKED

Operations to perform:
Unapply all migrations: photos Running migrations: Rendering model states... DONE
Unapplying photos.0001_initial... FAKED

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

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

追踪:追踪(最近通话最近一次):

Traceback:Traceback (most recent call last):

文件"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 execute return Database.Cursor.execute(self, query)

django.db.utils.OperationalError:表"photos_userphoto"已经存在

django.db.utils.OperationalError: table "photos_userphoto" already exists

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

要执行的操作:应用所有迁移:正在运行的照片迁移:正在应用photos.0001_initial ...伪造正在应用photos.0002_auto_20210303_0120 ...假

Operations to perform: Apply all migrations: photos Running migrations: Applying photos.0001_initial... FAKED Applying photos.0002_auto_20210303_0120... FAKED

运行上述命令后,我运行了 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:

将迁移标记为目标迁移(遵循上述规则)按应用,但没有实际运行SQL来更改您的数据库架构.

Marks the migrations up to the target one (following the rules above) as applied, but without actually running the SQL to change your database schema.

它还进一步指出,它是供高级用户手动进行更改的.基本上,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:

我已经或将要从数据库中手动删除所有表等用于应用程序照片

I have or will manually remove(d) all the tables, etc. from the database for the app photos

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:

我已经或将要手动创建数据库中的所有表等直到最近的迁移.

I have or will manually make all the tables, etc. in the database for the migrations till the most recent one.

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

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;零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆