How can I uninstall a Django app?

I am doing a bit of cleaning up an old project. The project has been upgraded to Django 1.8. There are several applications in the project that are no longer needed. I would like to uninstall these applications.

The problem is that you cannot uninstall an app with migrations because migrations of other apps might depend on them. For example ... app car

can be deleted, but the model in the application user

has a foreign key to the model in car

. If I uninstall the application car

then I get errors when doing full migrations. Migration in user

depends on migration in car

(a migration that creates a car model) and it will fail.

I can go back and edit migrations user

to remove all instances car

, acting as if it never existed. But then I can't have a migration that removes the property car

on user

, so the column will just stay in the database table (even if it's not used anymore).

How am I supposed to uninstall this app without delaying my migrations and leaving old columns around me?

+3


source to share


1 answer


It seems to me that you need to squash your migrations. Here's an outline of what you could do (migration only):



  • Add a hyphen that removes the dependency user

    on car

    .
  • Perform squash application migrations user

    .
  • Have a look at the new compressed migration - if it optimized the foreign key before car

    , that's ideal, otherwise manually remove the foreign key from the compressed migration history.
  • Make a release with new migrations (the one that removes the foreign key as well as the compressed one).
  • After all deployments have been updated (or after a reasonable depreciation cycle), delete the original hop chain, leaving only the squashed one behind.
+3


source







All Articles