3

I've stopped using a 3rd party app which I no longer need so I've uninstalled from my virtualenv. However, that causes all the old migrations which reference models from that app from failing when I migrate.

from menu.models import MenuItem
ImportError: No module named menu.models

The only two options I can think of are to either leave the 3rd party app installed just to satisfy the migration or to edit the old migration to remove the reference to the now defunct app.

Neither seem ideal. Any other way I've not thought of?

bodger
  • 1,112
  • 6
  • 24
  • 1
    You could try `squashmigrations` but that doesn't always work. Editing old migrations is normally the way I've had to do it.. (or I just leave the reference) – Sayse Jun 02 '16 at 14:42
  • Yes, I noticed the squashmigrations route. But that won't work in this case, I don't think, because the migrations that use the old model were actually creating instances of that model, so they won't get "squashed away" as it were. I guess I'll just have to edit the old migrations. – bodger Jun 02 '16 at 14:50
  • Yeah exactly, but for what its worth, I'd look at how much space the app actually takes up, if it isn't that much, it may not really be worth the time invested – Sayse Jun 02 '16 at 14:52
  • 1
    Good point.I suppose it's not that bad to keep the old app in there. I'm just a bit of a cleanfreak when it comes to requirements files and this one's a monster! – bodger Jun 02 '16 at 15:23

1 Answers1

0

According to Django Migrations Historical Models docs:

... the base classes of the model are just stored as pointers, so you must always keep base classes around for as long as there is a migration that contains a reference to them.

So, you should keep historical apps in your Virtualenv till you remove the migration files that have references to historical models. The ways to remove migrations files are:

  1. Squashing Migrations, or
  2. Removing migration files and migrations records in the database. CAUTION: Do NOT do that if you are not really sure what are you doing, look at this answers for more info: How to reset migrations in Django 1.7?.
Community
  • 1
  • 1
Cartucho
  • 3,257
  • 2
  • 30
  • 55