巩固Django南迁移 [英] Consolidating Django South Migrations

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

问题描述

在我的项目的初始阶段,我对模型做了很多更改,因此我结束了很多为我的应用程序生成的南迁移。在进入我的生产服务器执行迁移之前,是否可以以任何方式合并它们,所以我对每个应用程序没有一百万次迁移?

In the initial stages of my project I'm making a lot of changes to the models and thus I've ended up with a lot of south migrations being generated for my apps. Is it possible to consolidate them in any way before going to my production server to perform the migrations so I don't have like a million migrations for each app? And if so, how would I go about doing that?

推荐答案

您可以随时删除现有迁移和创建新的初始迁移

You could always delete the existing migrations and create a new "initial" migration.

要执行此操作,您需要:

To do this, you will need to:


  1. 删除应用程序的迁移文件)

  2. 运行 ./ manage.py convert_to_south myapp

  1. Remove the migration files for you app (remove the folder altogether)
  2. Run ./manage.py convert_to_south myapp


b $ b

这会让你对应于应用程序的状态当前状态的单个迁移。

This will leave you with a single migration corresponding to your app's state current state.

您可以随时将最新的迁移包装在一起:

Alternatively, you can always pack your latest migrations together:


  1. 删除要合并的迁移文件(仅当它们是最新的迁移) / li>
  2. 运行 ./ manage.py schemamigration myapp

  1. Remove the migration files that you want to merge (only if they are the latest onces)
  2. Run ./manage.py schemamigration myapp


$ b b

这将创建一个与您删除的迁移相对应的新迁移。

This will create a new migration that will correspond to the migrations you removed.

这两个都可能会弄乱你的开发数据库。

Both of these will likely mess up your development DB.

这篇关于巩固Django南迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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