--fake-initial与--fake在Django迁移中? [英] --fake-initial vs --fake in Django migration?

查看:229
本文介绍了--fake-initial与--fake在Django迁移中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Django迁移中,-fake-initial -fake 有什么区别?使用假迁移有什么危险?有人知道吗非常感谢大家。

What is the difference between --fake-initial and --fake in Django migrations? What are the dangers of using fake migrations? Anybody knows? Thank you very much to all.

我正在使用django 1.10

I am using django 1.10

推荐答案

文件对此非常清楚


如果所有数据库
表具有该迁移中所有CreateModel
操作创建的所有模型的名称,则允许Django跳过应用程序的初始迁移。此选项供
使用,当
首次运行迁移到已预先使用迁移的数据库时。但是,此选项不会检查
匹配表名称之外的匹配数据库模式

Allows Django to skip an app’s initial migration if all database tables with the names of all models created by all CreateModel operations in that migration already exist. This option is intended for use when first running migrations against a database that preexisted the use of migrations. This option does not, however, check for matching database schema beyond matching table names

您在问风险,好吧,这是

You were asking about the risks, well here it is


只有在您确信现有架构
与初始迁移中记录的内容匹配时才能安全使用

only safe to use if you are confident that your existing schema matches what is recorded in your initial migration.



-伪造



--fake


告诉Django将迁移标记为已应用或未应用
,但未实际运行SQL来更改您的
数据库架构。

Tells Django to mark the migrations as having been applied or unapplied, but without actually running the SQL to change your database schema.

如果高级用户手动进行更改,则可以直接操作当前的
迁移状态; <​​/ p>

This is intended for advanced users to manipulate the current migration state directly if they’re manually applying changes;

再次明确指出了风险


警告:使用--fake可能会使迁移
状态表进入手动恢复状态需要马ke
迁移正常运行。

be warned that using --fake runs the risk of putting the migration state table into a state where manual recovery will be needed to make migrations run correctly.

此答案不仅对Django 1.8+版本有效,对其他版本也有效。

This answer is valid not just for django versions 1.8+ but for other versions as well.

编辑,2018年11月:我有时在这里和其他地方看到答案,建议您删除数据仓库。那几乎从来都不是正确的事。如果删除数据库,则会丢失所有数据。

edit Nov, 2018: I sometimes I see answers here and elsewhere that suggest that you should drop your databae. That's almost never the right thing to do. If you drop your database you lose all your data.

这篇关于--fake-initial与--fake在Django迁移中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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