django - --fake-initial与--fake在Django迁移中?

标签 django django-models django-orm django-migrations

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

我正在使用Django 1.10

最佳答案

好吧,文档对此很清楚

--fake-initial

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



您是在问风险,好在这里

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



- 假

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

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



风险再次清晰地突出显示

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+版本有效,对其他版本也有效。

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

关于django - --fake-initial与--fake在Django迁移中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42695629/

相关文章:

python - 用于对象历史的 Model Mixin

mysql - Django - MySQL 数据库日期时间字段被清除

python - 如何使用 Django ORM 在没有数百个查询的情况下选择多对一?

python - 在django中直接提供外键值

android - 将数据从 Django 应用推送到 Android 应用

Django __str__ 返回非字符串(类型 NoneType)

django - 如何在 Django 中序列化模型实例?

Django+原始Sql查询: See raw sql query running behind Django ORM in get method

django - 如何通过ajax发送django文本和图片形式

mysql - 提交运行 Django 应用程序所需的所有 MySQL 设置的好方法是什么?