Troy
Troy

Reputation: 21892

Django (1.7) is placing migrations in the wrong app

I have a project structure something like the following:

models.py:

project
    parentapp
        __init__.py
        models.py
        migrations
            __init__.py
        subapp1
            models.py
            migrations
                __init__.py
        subapp2
            models.py
            migrations
                __init__.py
    project
        __init__.py
        settings.py

settings.py:

INSTALLED_APPS = (
    'django.contrib.admin',
    ...
    'parentapp',
    'parentapp.subapp1',
    'parnetapp.subapp2',
)

Then I run

python manage.py makemigrations

It places parentapp's migrations in parentapp/migrations/ (as it should).
It places subapp1's migrations in subapp1/migrations/ (as it should).
However, it places subapp2's migrations in parentapp/migrations/, rather than in subapp2/migrations/...

Even if I run python manage.py makemigration subapp2, it still places subapp2's migrations in the wrong folder. Aside from just being weird, when Django does that, any attempts to create a model in the subapp2 app will fail with ProgrammingError: relation "parentapp_somesubapp2model" does not exist".

To get around the problem for now, I can manually hack up a migration for subapp2, but, for future reference, and to avoid the problem in the future, How does Django decide when the subapp's migrations should go in the parent app, and when they should go in the subapp folder?
Is there a way to force it one way or the other?

Upvotes: 1

Views: 217

Answers (1)

mcastle
mcastle

Reputation: 2982

In settings, you can set the MIGRATION_MODULES dictionary explicitly and pass in the correct location of an app's migrations:

MIGRATION_MODULES = {
 'subapp2': 'subapp2.migrations'
}

Upvotes: 3

Related Questions