Django South: Creating schemamigration for more than one app

女生的网名这么多〃 提交于 2019-12-05 08:54:15

问题


I'M using django south on a bigger project, the only thing I don't like about it, that you can't create schemamigrations for all of your apps at once (I have a lot of apps that inherit from the same abstract model, if I change that base model there are alot of apps to migrate) - thought you can actually migrate all of them at once (using migrate --all).

So I'd like to know if theres an easy solution for django south to handle a bunch of apps at once or if anyone has a nice script ready for doing that?


回答1:


First thing: separate applications should limit model interactions

now that it's said, let's embrace the constraint. No south cannot create a single migration file for many apps and I don't know how to generate many migrations for many app in a single manage.py command.

All that is left to you is a script now. You could use the amazing fabric http://docs.fabfile.org/ to have a single command to generate your migrations :

APPS_TO_WATCH = ['myapp','myotherapp','toomanyapps']
def migration():
    for app in APPS_TO_WATCH:
        local('python manage.py schemamigration %s --auto' % app)

and then call it using fab migration




回答2:


This is not quite an answer to your question, but might help out depending on exactly what you are trying to do.

You can define migrations as depending on migration(s) from other apps. For example:

class Migration(SchemaMigration):
    depends_on = (
        ("other_app", "0001_initial"),
    )

This will ensure all required pre-requisite migrations have been run before yours.




回答3:


An addition to the fabric answer above, add this to your fabfile.py:

from myproj.settings import INSTALLED_APPS

def initmigration():
    for app in INSTALLED_APPS:
        if 0 == app.find('myproj.'):
            _app = app.split('myproj.')[1]
            local('python manage.py convert_to_south %s' % _app)

Now run fabric initmigration. Can do similar thing for the migration function above.



来源:https://stackoverflow.com/questions/3166284/django-south-creating-schemamigration-for-more-than-one-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!