[Answer]-Django redistributable app with south

1👍

You just need to add the app to your Installed_Apps in your settings.py

Then you can run ./manage.py schemamigration <app_name> --auto

If the app doesn’t have any migrations you will want to run ./manage.py schemamigration <app_name> --initial first and then ./manage.py schemamigration <app_name> --auto from then on.

👤nates

0👍

Just managed to get this working in one of my project. Here’s the code that works for me:

import sys

from django.conf import settings
from django.core.management import call_command


if not settings.configured:
    settings.configure(
        ROOT_URLCONF='',
        DEBUG=False,
        DATABASES={
            'default': {
                'ENGINE': 'django.db.backends.sqlite3',
                'NAME': 'test.db'
            }
        },
        INSTALLED_APPS=(
            'south',
            'my_app',
        )
    )

if __name__ == "__main__":
    call_command('schemamigration', 'my_app', 
                 initial=len(sys.argv) > 1,
                 auto=len(sys.argv) == 0

The above script is saved as migrate.py and run with python migrate.py or python migrate.py i (the i can be anything, and it will use --initial instead of --auto if present). Obviously, you can do fancier command line option parsin, but this works for me.

EDIT: Updated the script, DATABASES key was missing. On this project, I used the same database for testing the code, so it’s not an entirely arbitrary configuration.

Leave a comment