[Django]-How to delete an app from a django project

50👍

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.

0👍

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.

0👍

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:\python\releases\381_x64\lib\threading.py", line 932, in _bootstrap_inner
  [...]
  File "c:\python\env\django3python381\lib\site-packages\django\db\migrations\graph.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

👤jerome

Leave a comment