Search code examples
djangodependenciesdatabase-migrationdjango-south

Django migrations missing way to declare "needed_by"?


If you have two apps:

  • core_app
  • plugin_app

The core does not need the optional plugin.

Up to now we used south and could use needed_by if a migration of the plugin needs to run before a migration of the core app.

I could not find something in the docs: https://docs.djangoproject.com/en/1.8/topics/migrations/

Related. The old south docs: http://south.aeracode.org/wiki/Dependencies

How to tell the new django migrations to run a plugin migration before a core migration?

Of course I don't want to change the source of the core and add a dependency to the plugin migration. This must not be done, since the core should run without the plugin.


Solution

  • You should use the run_before attribute:

    class Migration(migrations.Migration):
        run_before = [
            ('core_app', '0001_initial'),
        ]