使用Django South重新设置迁移历史记录的建议方法是什么? [英] What's the recommended approach to resetting migration history using Django South?

查看:107
本文介绍了使用Django South重新设置迁移历史记录的建议方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用南(0.7)和Django(1.1.2)积累了不少迁移,这些迁移在我的单元测试中开始耗费相当多的时间。我想重置基线并开始一整套迁移。我已经查看了南方文档,完成了通常的Google / Stackoverflow搜索(例如django南部(重置或删除或删除)迁移历史记录),并没有发现任何明显的东西。

I've accumulated quite a few migrations using South (0.7) and Django (1.1.2) which are starting to consume quite a bit of time in my unit tests. I would like to reset the baseline and start a fresh set of migrations. I've reviewed the South documentation, done the usual Google/Stackoverflow searching (e.g. "django south (reset OR delete OR remove) migration history") and haven't found anything obvious.

我预期的一种方法将涉及重新启动 手动清除或清除历史记录(例如,清除数据库表,从迁移主管中删除迁移文件),然后重新运行

One approach I've contemplated would involve "starting over" by "removing" South or "clearing" the history manually (e.g. clear the db table, remove migration files from the migrations director) and just re-run,


./ manage.py schemamigration southtut --initial

./manage.py schemamigration southtut --initial

所以,如果有人以前做过这些,并提供一些提示/建议,将不胜感激。

So, if anyone has done this before and has some tips/suggestions they would be greatly appreciated.

推荐答案


编辑 - 我在下面发表评论这是因为在@andybak之前的>接受的答案之后阅读它很重要

EDIT - I'm putting a comment below at the top of this as it's important to read it before the > accepted answer that follows @andybak


@Dominique:你的建议保存manage.py reset south是危险的
,如果有任何第三方应用程序在项目中使用
南部,可能会破坏数据库,如下面的@thnee所指出的。因为你的
答案有很多upvote我真的很感激,如果你可以编辑
它,并添加至少一个警告,或(甚至更好)更改
反映@hobs方法(这是一样方便,但
不影响其他应用程序) - 谢谢! - chrisv Mar 26 '13 at 9:09

@Dominique: Your advice regarding manage.py reset south is dangerous and may destroy the database if there are any third party apps using south in the project, as pointed out by @thnee below. Since your answer has so many upvotes I'd really appreciate it if you could edit it and add at least a warning about this, or (even better) change it to reflect @hobs approach (which is just as convenient, but doesn't affect other apps) - thanks! – chrisv Mar 26 '13 at 9:09

接受的答案如下:

首先,答案由南方作家


只要您在所有部署中同时执行,不应该任何问题。个人来说,我会这样做:

As long as you take care to do it on all deployments simultaneously, there shouldn't be any problem with this. Personally, I'd do:

    rm -r appname/migrations/ 
    ./manage.py reset south 
    ./manage.py convert_to_south appname 

(注意重置南部部分清除所有应用程序的迁移记录,因此请确保您运行其他两行所有应用程序或有选择地删除)。

(Notice that the "reset south" part clears migration records for ALL apps, so make sure you either run the other two lines for all apps or delete selectively).

convert_to_south 调用最后会进行新的迁移和假冒 - 应用它(因为你的数据库已经有相应的表)。在此过程中,不需要删除所有的应用程序表。

The convert_to_south call at the end makes a new migration and fake-applies it (since your database already has the corresponding tables). There's no need to drop all the app tables during the process.

这是我在我的开发人员+生产服务器上做的需要摆脱所有这些不必要的开发人员迁移:

Here's what I'm doing on my dev + production server when I need to get rid of all these unneeded dev migrations:


  1. 确保我们在双方拥有相同的数据库模式

  2. 删除双方的每个迁移文件夹

  3. 运行./manage.py重置南(作为帖子说)双方=清除南表*

  4. 在双方运行./manage.py convert_to_south (伪造0001迁移)

  5. 然后我可以重新启动进行迁移推送我的服务器上的迁移文件夹

  1. Make sure we have the same DB schema on both sides
  2. delete every migrations folder on both sides
  3. run ./manage.py reset south (as the post says) on both sides = clears the south table *
  4. run ./manage.py convert_to_south on both sides (faking 0001 migration)
  5. then I can re-start to make migrations and push the migrations folders on my server

*除非你想清除只有一个应用程序,否则,你需要编辑您的south_history表,并仅删除有关您的应用程序的条目。

* except if you want to clean only one app among others, if so you'll need to edit your south_history table and delete only the entries about your app.

这篇关于使用Django South重新设置迁移历史记录的建议方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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