目前使用Django“Evolution”,是“South”更好和值得转换? [英] Currently using Django "Evolution", is "South" better and worth switching?

查看:126
本文介绍了目前使用Django“Evolution”,是“South”更好和值得转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Django演进来管理我的产品的数据库发展。这不完美,但我已经学会了生活中的缺陷。例如,由于演进命令不能始终发展出几个小迁移中已更改的数据库,所以我必须先复制我的生产数据库进行测试,然后再进行测试(在测试中我做了A-> B-> C,但是A-> C不会正确演变。)

I'm currently using Django evolutions to manage my product's database evolutions. It's not perfect but I've learned to live with its flaws. For instance, I always have to copy my production database to test before moving out a new schema because the "evolve" command cannot always evolve a database that was changed in several small migrations (on test I did A->B->C, but A->C will not evolve correctly.)

南方会解决所有这些问题吗?引导新工具的价值是值得的吗?

Will South fix all of those problems? Is it worth the effort of learing a new tool?

推荐答案

我刚开始使用南方,它。这也是少数仍然处于非常积极的发展之一。

I just started using South, and I'm 100% sold on it. It's also one of the few that's still under very active development.

南方应该能够妥善处理上述问题。对于db的每次更改,它都会创建一个文件,该文件有两种方法foward和backwards。以下是自动生成的迁移示例:

South should be able to properly handle the issues you've describe above. For each change to the db, it creates a file that has 2 methods "foward" and "backwards". Here's a sample automatically generated migration:

# > manage.py schemamigration issuetracker added-status-field --auto

# 0004_added-status-field.py
class Migration:

    def forwards(self, orm):

        # Adding field 'Issue.status'
        db.add_column('issuetracker_issue', 'status', orm['issuetracker.issue:status'])       

    def backwards(self, orm):

        # Deleting field 'Issue.status'
        db.delete_column('issuetracker_issue', 'status')

一些关于它的好东西....

A couple of the nice things about it....


  • 如果您希望

  • South lets you rollback to a specific migration # if you'd like

如果您的生产站点正在迁移0002,则South可让您回滚到特定迁移#你的SVN提交是在0004,南将做0003然后0004,以使生产数据库达到速度。

If your production site is on migration 0002 and your SVN commit is on 0004, South will do 0003 then 0004 to bring the production db up to speed.

如果你已经进行了更改你自己可以告诉南方,进行假冒迁移。通常情况下,迁移系统会引发嘶嘶作风,但这样可以很容易地对数据库进行灵活控制。

If you've gone ahead and made the changes yourself, you can tell South to run a 'fake' migration. Normally a migration system would throw a hissy fit, but this makes it really easy to have flexible control over your db.

manage.py migrate [ appname] --fake

如果您需要自定义事情,例如将列中的数据复制到另一列,因为迁移文件只是python文件,很容易修改前向/后向的功能。

If you need to have something custom happen, like say copying the data in a column to another column, because the migration files are just python files it's easily to modify the forward/backwards functions.

在部署了应用程序后迁移到南很简单。最新版本0.6包含了一个命令。

Migrating to South after having already deployed an application was rather easy. The latest version 0.6 includes a command for it actually.

manage.py convert_ to _south [appname]

当然,我怎么会忘记,我最喜欢的功能是自动生成迁移文件

And of course, how could I forget, my favorite feature is the automatic generation of migration files

manage.py schemamigration [appname] [description] --auto

我想我应该添加一些提示,当我开始使用南方时,我犯了错误。不是一切都是100%直观的。

I figured I should add in some tips for mistakes I made when getting started with South. Not everything is 100% intuitive.


  • 在开发数据库上运行convert_to_south命令后,不要忘记在您的生产数据库中运行 migrate --fake ,否则南方会认为它已经过时。

  • After you've run the convert_to_south command on your development database, don't forget to run migrate --fake on your production database, otherwise South will think it's out of date.

如果您正在创建一个新的应用程序,请使用 - 初始标志

If you're creating a new app, you use the --initial flag

停止使用管理.py syncdb。

Stop using manage.py syncdb. Really.

编辑模型是一个3步的过程 -

Editing a model is a 3 step process --

1。)保存模型更改

2。)运行 schemamigration --auto

3。)运行 migrate 实际提交对数据库的更改

3.) run migrate to actually commit the changes to the database

编辑 - 为了澄清下面的意见,南方正式被核心贡献者投票,不包括在1.2版本中。这部分是因为南方的作者要求它尚未被列入。尽管如此,南方还是有很多社区支持,有些可重复使用的应用程式制作人员正在开始使用他们的应用程式纳入南移。

Edit -- To clarify the comments below, South was officially voted by the core contributors to not be included with Version 1.2. This was in part because the author of South had requested that it not yet be included. Even still, there is a lot of community support for South, and some reusable app makers are beginning to include South migrations with their app.

编辑#2 - - 我做了一些更新,以反映来自South的当前中继版本的新的manage.py命令结构。 开始迁移已被拆分为schemamigration和datamigration,取决于您正在做什么。

Edit #2 -- I made some updates to reflect the new manage.py command structure from the current trunk version of South. "startmigration" has been split to "schemamigration" and "datamigration" depending on what you're doing.

这篇关于目前使用Django“Evolution”,是“South”更好和值得转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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