2013-12-23 111 views
5

我目前没有在我的Django项目中使用迁移,但我打算很快。据我所知,South是事实上的工具,我打算使用它,但后来我在Django项目网站上看到开发版本(我猜想发布为1.7)有一个核心迁移工具,运行时为migrateDjango的核心迁移工具与南方的Django数据迁移

来自使用迁移工具的很少经验(我在南方安装了Django-CMS并在它上面玩了一天左右),这对于初学者来说是最好的吗?

另外,由于迁移本身非常年轻,而且Django的版本更加如此,那么在南方这点上我会更好吗?

最后,另一个问题是,如果我从南开始(我的大部分Django项目都是v1.5),当我升级到1.6然后升级到1.7时,我会无法转换为Django的核心迁移?

+0

相关问题:如何提供从南应用程序到Django 1.7迁移的升级路径http://stackoverflow.com/questions/22597240/upgrade-path-for-re-usable-apps-with-south-and-django -1-7迁移 – stefanfoulis

回答

3

它容易丢弃南迁移历史并初始化任何其他类型的迁移工具。

Django核心迁移基于南,所以我猜测它将有可能将南迁移历史导出到Django核心迁移。

由于Django核心迁移还没有发布,而你的目的是学习,所以我建议从南开始。

+0

我安装了南部并转换了我的应用程序,它运行得很好。由于我还没有准备好升级Django,所以这个计划似乎是个好主意。谢谢。 – nicorellius

4

由于安德鲁戈德温(创造者或Django核心迁移)关于这一变化的话是:“南的四年设计严重的限制,是时候增加迁移支持到Django本身”,我不会赌将南迁移历史导出到Django核心迁移的能力。这就是为什么,如果可以的话,我建议你等待1月20日:核心迁移的Django 1.7 alpha版本将被发布,你可以看到here

最终,Andrew Godwin worked on South himself,所以你不应该看到Django Core Migration作为一个整体的新工具,而是作为South v2。

然后,你可以很确定,只要Core迁移发布,South就不会真正维护。

这就是为什么我建议等待一些时间,并给予一个机会,这个新工具:)

+0

好点+1 ... – nicorellius

3

从南Django的1.7升级讨论的文件:

If you already have pre-existing migrations created with South 0.x, then the upgrade process to use django.db.migrations is quite simple:

  • Ensure all installs are fully up-to-date with their migrations
  • Delete all your (numbered) migration files, but not the directory or init.py - make sure you remove the .pyc files too.
  • Run python manage.py makemigrations. Django should see the empty migration directories and make new initial migrations in the new format.
  • Run python manage.py migrate. Django will see that the tables for the initial migrations already exist and mark them as applied without running them.

That’s it! The only complication is if you have a circular dependency loop of foreign keys; in this case, makemigrations might make more than one initial migration, and you’ll need to mark them all as applied using:

python manage.py migrate --fake yourappnamehere 

(从here)。

+0

> Django会看到初始迁移的表已经存在,并将它们标记为已应用而不运行它们。 显然,并不总是如此。我收到错误“django.db.utils.OperationalError:table”[table]“already exists”。正在运行迁移应用程序0001 --fake会修复它。 – wes