[Answered ]-What is the best way to remove a third-party Django app with models in database?

1👍

First make sure none of your models have any dependency to this third party app, so no foreign keys, one to one fields, many to many relations, etc. Remove any of these and migrate.

Next you want to migrate the changes this app made to zero so you can run the following command:

python manage.py migrate <third_party_appname> zero

Referred from the documentation on migrate [Django docs]:

<app_label> <migrationname>: Brings the database schema to a state where the named migration is applied, but no later migrations in the
same app are applied. This may involve unapplying migrations if you
have previously migrated past the named migration. You can use a
prefix of the migration name, e.g. 0001, as long as it’s unique for
the given app name. Use the name zero to migrate all the way back
i.e. to revert all applied migrations for an app.

This will revert all changes made to the database and now you can freely remove it from INSTALLED_APPS.

Leave a comment