Search code examples
djangodjango-southdata-migration

Run south default data migrations for built-in applications such as auth.group or flatpages?


The issue at hand is that in order to install default data into the database for built-in django applications such as flatpages or auth.group requires specifying SOUTH_MIGRATION_MODULES although the South documentation isn't very clear regarding the directory structure and the way to generate such data migrations.

Any ideas how to do this?


Solution

  • It's not necessary to use South for this, you can use an initial fixture which is auto loaded when you do a syncdb:
    https://docs.djangoproject.com/en/dev/howto/initial-data/#automatically-loading-initial-data-fixtures

    The docs do note that from Django 1.7 onwards this is deprecated (in fact syncdb itself is deprecated) and you should make a data migration using the new built-in migrations functionality, which supersedes South:
    https://docs.djangoproject.com/en/dev/topics/migrations/#data-migrations

    If you want to use South migrations for say django.contrib.auth.models.Group then I think you can do it like this:

    /projectroot/
    /projectroot/myapp
    /projectroot/myapp/migrations
    /projectroot/myapp/migrations/__init__.py
    /projectroot/myapp/migrations/auth/__init__.py
    /projectroot/myapp/migrations/auth/0001_initial_groups.py  # arbitrary name
    

    (any structure that results in a sane Python dotted import path to your actual migration from your project code)

    Then in settings:

    SOUTH_MIGRATION_MODULES = {
        'auth': 'myapp.migrations.auth',
    }