4

I am doing some clean up on an old project. The project has been upgraded to Django 1.8. The project has several apps that are no longer needed at all. I'd like to remove these apps.

The problem is that you can't remove an app with migrations because other apps' migrations might depend on them. For instance...app car can be removed, but a model in app user has a foreign key to a model in car. If I remove the car app then I will get errors when the full migrations run. A migration in user depends on a migration in car (the migration that creates the Car model) and it will fail.

I can go back and edit the user migrations to remove all instances of car, acting as if it never existed. But then I can't have a migration that removes the car property on User, so that column will just remain in the database table (even though it is no longer used).

How am I supposed to remove this app without borking my migrations and leaving old columns laying around?

grantmcconnaughey
  • 10,130
  • 10
  • 37
  • 66
  • 2
    i hope this http://stackoverflow.com/questions/3329773/django-how-to-completely-uninstall-a-django-app – Jmint May 15 '15 at 17:43

1 Answers1

3

It sounds to me like you need to squash your migrations. Here's an outline of what you could do (only as far as migrations are concerned):

  1. Add a migration that removes the dependency of user on car.
  2. Squash the migrations of the user app.
  3. Look at the new squashed migration – if it optimized the foreign key to car away, that's perfect, otherwise, remove the foreign key from the squashed migration history manually.
  4. Make a release with both new migrations (the one that removes the foreign key, as well as the squashed one).
  5. After all deployments have been upgraded (or after a reasonable deprecation cycle), remove the original chain of migrations, leaving only the squashed one behind.
koniiiik
  • 4,240
  • 1
  • 23
  • 28