derbauio
derbauio

Reputation: 3

Django run migration before 3rd party app migration

I'm installing a 3rd party app, but needed to rename one of my apps as the names clashed. As part of this renaming I needed to write a migration to update django_content_type and django_migrations tables.

The trouble is when the migrations run, the 3rd party app migrations run before mine. How can I force mine in to run before the 3rd party apps?

Current migration code:

class Migration(migrations.Migration):

dependencies = [
    migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ('my_cms', '0003_promotedsearch_title_it'),
]

operations = [
    migrations.RunSQL(
        'UPDATE django_content_type SET app_label=\'my_cms\' '
        'WHERE app_label=\'cms\';'
    ),
    migrations.RunSQL(
        'UPDATE django_migrations SET app=\'my_cms\' WHERE app=\'cms\';'
    ),
]

thanks

Upvotes: 0

Views: 770

Answers (2)

Nikita
Nikita

Reputation: 6331

There're dependencies and run_before that help you order the migrations. See: https://docs.djangoproject.com/en/1.9/howto/writing-migrations/#controlling-the-order-of-migrations

In your case, you need to provide run_before list in your migrations containing 3rd party app migrations. This will make your migration run before those specified in the list.

Upvotes: 1

arcegk
arcegk

Reputation: 1480

Try to delete the third party app of your INSTALLED_APPS settings variable and migrate, then put it in INSTALLED_APPS again.

Upvotes: 1

Related Questions