How to delete an app from a django project

Question:

Initially I made 2 apps (app_a and app_b) in a single project in Django. Now I want to delete one (say app_a). How should I do so? Is removing the app name from INSTALLED_APPS in the settings file sufficient?

Asked By: nimeshkiranverma

||

Answers:

You need to remove or check the following:

  • Remove the app from INSTALLED_APPS.
  • Remove any database tables for the models in that app (see app_name_model_name in your database).
  • Check for any imports in other apps (it could be that they’re importing code from that app).
  • Check templates if they are using any template tags of that app (which would produce errors if that app is no longer there).
  • Check your settings file to see if you’re not using any code from that app (such as a context processor in your_app/context_processors.py, if it has such as file).
  • Check if any static content of the app is used in other apps.
  • Remove the app directory entirely.

When you’ve been following proper coding principles (i.e., each Django app is a self-contained part of the web application) then most situations above won’t occur. But when other apps do use some parts of that app, you need to check that first as it may require refactoring before deleting the app.

Answered By: Simeon Visser

It depends on the app (how it was installed, how it was used, etc) but usually you can remove app from INSTALLED_APPS and then delete its tables in the database.

Answered By: machaku

if, after the operations explained by Simeon Visser and in the other answer referenced by Elias Dorneles in the comments, you get somthing like this after a runserver :

System check identified 1 issue (0 silenced).
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:pythonreleases381_x64libthreading.py", line 932, in _bootstrap_inner
  [...]
  File "c:pythonenvdjango3python381libsite-packagesdjangodbmigrationsgraph.py", line 58, in raise_error
    raise NodeNotFoundError(self.error_message, self.key, origin=self.origin)
django.db.migrations.exceptions.NodeNotFoundError: Migration oeuvres.0001_initial dependencies reference nonexistent parent node ('medias', '0001_initial')

browse to your appname.migrations folder and comment any references to the app you want to remove. In the case above, the oeuvres app had a dependency to the medias app, which I want to remove, defined in the oeuvres.0001_initial migration file.

I don’t think/don’t know yet if this will have consequences on the migration processes but I intend to reset all migrations stuff for production then import datas ie as described here :
https://simpleisbetterthancomplex.com/tutorial/2016/07/26/how-to-reset-migrations.html

Answered By: jerome
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.