title: Django migration dependency order
body: <p>I have a relatively complex set of Django models. I'm trying to start with a fresh set of migrations (<code>rm -rf apps/*/migrations; bin/dev/manage.py makemigrations A B C...</code>). <code>makemigrations</code> works fine, and there are no circular dependencies, but I'm consistently getting an <code>InconsistentMigrationHistory</code> exception when I migrate. Here's a graph of the dependencies between the migrations, simplified to remove the migrations with no related dependencies, and with the app names redacted for readability:
  <a href="https://i.stack.imgur.com/iKwpt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iKwpt.png" alt="Migration dependencies"></a>
   The links in red cause the error (different ones each time I run <code>migrate</code>), even with a <code>run_before</code> added to each migration that should be run before its dependency:</p>
  
  <p>A/migrations/0002_whatever.py:</p>
  
  <pre><code>...
  run_before = [('P', '0001_initial'),]
  </code></pre>
  
  <p>Here's the error text.</p>
  
  <pre><code>django.db.migrations.exceptions.InconsistentMigrationHistory: Migration `P.migrations.0001_initial` is applied before its dependency `A.migrations.0002_whatever` on database 'default'.
  </code></pre>
  
  <p>Any ideas?</p>