I have a few projects with lots of South migrations, including ones that contain a fair amount of custom SQL that need to be run in a specific order. After upgrading to Django 1.7, this is the recommendation on how to convert a project to use South (from the Django documentation):
我有一些包含大量南迁移的项目,包括需要按特定顺序运行的大量自定义SQL的项目。升级到Django 1.7后,这是关于如何将项目转换为使用South的建议(来自Django文档):
If you already have pre-existing migrations created with South, then the upgrade process to use django.db.migrations is quite simple:
如果您已经使用South创建了预先存在的迁移,那么使用django.db.migrations的升级过程非常简单:
- Ensure all installs are fully up-to-date with their migrations.
确保所有安装都与其迁移完全保持同步。
- Remove 'south' from INSTALLED_APPS.
从INSTALLED_APPS中删除“south”。
- Delete all your (numbered) migration files, but not the directory or
__init__.py
- make sure you remove the .pyc files too.删除所有(编号)迁移文件,但不删除目录或__init__.py - 确保也删除.pyc文件。
- Run python manage.py makemigrations. Django should see the empty migration directories and make new initial migrations in the new format.
运行python manage.py makemigrations。 Django应该看到空的迁移目录并以新格式进行新的初始迁移。
- 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.
运行python manage.py migrate。 Django将看到初始迁移的表已经存在,并将它们标记为已应用而不运行它们。
In short, "wipe your existing migrations and Django will take care of the rest".
简而言之,“擦除您现有的迁移,Django将负责其余的”。
What is not mentioned here is what to do when existing South migrations don't only consist of model changes, but instead contain direct SQL, data migrations, etc, that need to be run in order. In this case, the auto-generated Django migrations will miss a lot of things, since not all of these changes are obvious from introspecting a models file.
这里没有提到的是,当现有的南迁移不仅包括模型更改,而是包含需要按顺序运行的直接SQL,数据迁移等时,该怎么办。在这种情况下,自动生成的Django迁移将遗漏很多东西,因为并不是所有这些变化都可以从内省模型文件中看出来。
Ideally, one would be able to run the existing migrations using South, and then have Django migrations take over. What might be the best way to go about this? If this is not possible or very much not recommended, what is the best alternative?
理想情况下,一个人可以使用South运行现有的迁移,然后让Django迁移接管。什么是最好的方法呢?如果这是不可能的或非常不推荐,最好的选择是什么?
1 个解决方案
#1
3
Maybe this post can help you. Essentially you have to:
也许这篇文章可以帮到你。基本上你必须:
- Change your current migration directory from 'migrations' to 'south_migrations'
-
Update your settings with this line
使用此行更新您的设置
SOUTH_MIGRATION_MODULES = { 'your_app': 'your_project.your_app.south_migrations', }
SOUTH_MIGRATION_MODULES = {'your_app':'your_project.your_app.south_migrations',}
将当前迁移目录从“迁移”更改为“south_migrations”
#1
3
Maybe this post can help you. Essentially you have to:
也许这篇文章可以帮到你。基本上你必须:
- Change your current migration directory from 'migrations' to 'south_migrations'
-
Update your settings with this line
使用此行更新您的设置
SOUTH_MIGRATION_MODULES = { 'your_app': 'your_project.your_app.south_migrations', }
SOUTH_MIGRATION_MODULES = {'your_app':'your_project.your_app.south_migrations',}
将当前迁移目录从“迁移”更改为“south_migrations”