0

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

derbauio
  • 3
  • 2

2 Answers2

1

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

arcegk
  • 1,480
  • 12
  • 15
1

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.

Nikita
  • 6,101
  • 2
  • 26
  • 44