Renaming model breakes migration history
<p>I have two models in two different apps:</p>

<pre><code># app1 models.py
class App1Model(models.Model):
    pass


# app2 models.py
from app1.models import App1Model

class App2Model(App1Model):
    pass
</code></pre>

<p>And I want to rename App1Model and then recreate App2Model to have explicit <code>OneToOneField</code> instead of magic <code>app1model_ptr</code>. So I create migration which deletes App2Model completely (I don't care about data because whatever reason), it runs successfully. Then I create migration in first app which renames App1Model and it runs perfect too, I check this table with new name and all it's relationships (and to it too), it's fine.</p>

<p>And then weird thing happens: when I run <code>makemigrations</code> or <code>migrate</code> on app2 I get an error </p>

<pre><code>django.db.migrations.exceptions.InvalidBasesError: Cannot resolve bases for [&lt;ModelState: 'app2.App2Model'&gt;]
</code></pre>

<p>It fails while creating current project state on very first migration of app2 (0001_initial.py in app2 migrations) where this model was created first time by inheriting from App1Model with its old name.
Is there some way of fixing this? In current state <code>App2Model</code> already deleted, <code>App1Model</code> renamed and I can't do anything with migrations on app2 because of this issue.</p>

<p>P.S. I use Django 1.10.2</p>

<p>Just found solution:</p>

<p>Need to add last migration of <code>app2</code> where I deleted <code>App2Model</code> as dependency to migration of <code>app1</code> where I renamed <code>App1Model</code> so project state will be built in correct order. Actually error message itself has something related to it but I failed to catch the point: </p>

<blockquote>
  <p>This can happen if you are inheriting models from an app with
  migrations (e.g. contrib.auth) in an app with no migrations; see
  <a href="https://docs.djangoproject.com/en/1.10/topics/migrations/#dependencies" rel="nofollow">https://docs.djangoproject.com/en/1.10/topics/migrations/#dependencies</a>
  for more</p>
</blockquote>

<p>I put it here for future me and for those who will suffer from similar thing.</p>

python django database-migration