Django 1.8 压缩迁移

Django 1.8 Squashing migrations

我对 Django 1.8 中的 Squashing 有一些疑问。我已将几个迁移文件压缩为一个,但不太确定如何执行 djangoprojects 文档中指定的 2 个操作。

After this has been done, you must then transition the squashed migration to a normal initial migration, by:

-Deleting all the migration files it replaces

-Removing the replaces argument in the Migration class of the squashed migration (this is how Django tells that it is a squashed migration)

  1. 是否只使用普通rm命令删除迁移文件中的迁移文件?
  2. 我是否只 vim 迁移文件“0001_squashed_xxx”并删除部分“replaces = []”?
  3. 另外,我运行压缩迁移后,迁移(原来是0010)自动变成了0001。这是预期的行为吗?

任何帮助都会很棒。谢谢!

  1. Do I just delete the migration files in the migration file using normal rm command?
  2. Do I just vim the migration file "0001_squashed_xxx" and remove the part "replaces = []"?

是的,是的,但只有在您 运行 所有生产站点上的压缩迁移之后。 此外,您应该确保 none 的其他迁移取决于您将要删除的迁移。如果他们这样做,您应该更改这些依赖项以指向相应的压缩迁移。

  1. Also, after I run the squashed migration, the migration (original is 0010) became 0001 automatically. Is this the expected behavior?

这是因为压缩的迁移被赋予了名称 <start_migration>_squashed_<end_migration>。因此,如果您从 0001_initial 压缩到 0010_blah,压缩后的迁移将具有名称 0001_initial_squashed_0010_blah,因此其代码将以 0001 开头。但是编号并没有真正的意义,它只是为了让您的迁移在目录中列出时很好地排序。