Django: How to completely uninstall a Django app?
What is the procedure for completely uninstalling a Django app, complete with database removal?
Solution 1:
Django < 1.7 has a handy management command that will give you the necessary SQL to drop all the tables for an app. See the sqlclear docs for more information. Basically, running
./manage.py sqlclear my_app_name
gets you get the SQL statements that should be executed to get rid of all traces of the app in your DB. You still need to copy and paste (or pipe) those statements into your SQL client. For Django 1.7 and up, use./manage.py migrate my_app_name zero
(see the migrate docs), which runs the database cleaning automatically.To remove the app from your project, all you need to do is remove it from
INSTALLED_APPS
in your project'ssettings.py
. Django will no longer load the app.If you no longer want the app's files hanging around, delete the app directory from your project directory or other location on your PYTHONPATH where it resides.
(optional) If the app stored media files, cache files, or other temporary files somewhere, you may want to delete those as well. Also be wary of lingering session data that might be leftover from the app.
(optional) I would also remove any stale content types.
Like so.
from django.contrib.contenttypes.models import ContentType
for c in ContentType.objects.all():
if not c.model_class():
print "deleting %s"%c # print(f"deleting {c}") # for Python 3.6+
c.delete()
Solution 2:
- comment out on
settings.py
inINSTALLED_APPS
unnecessary app's line - delete all folder
__pycache__
andmigrate
at your project - delete unnecessary model in
models.py
- delete all import link in
views.py
,admin.py
end etc. - delete all link's in
urls.py
on your unnecessary app's - in database delete unnecessary tables wich associated with the app (I do it with help program "Valentina Studio")
- delete app's folder
- in command line do it:
python manage.py migrate
andpython manage.py syncdb