Django:如何彻底卸载Django应用程序? [英] Django: How to completely uninstall a Django app?
问题描述
完全卸载Django应用程序的步骤是什么,完成数据库删除?
What is the procedure for completely uninstalling a Django app, complete with database removal?
推荐答案
-
Django有一个方便的管理命令,它将为您提供必要的SQL来删除应用程序的所有表。请参阅 sqlclear docs 了解更多信息。基本上,运行
./ manage.py sqlclear my_app_name
,您将获得应执行的SQL语句,以摆脱数据库中应用程序的所有痕迹。您仍然需要将这些语句复制粘贴(或管道)到您的SQL客户端。
Django 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
you'll 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.
要从项目中删除该应用程序,您只需要做的就是从项目的 settings.py
中的 INSTALLED_APPS
中删除它。 Django将不再加载应用程序。
To remove the app from your project, all you need to do is remove it from INSTALLED_APPS
in your project's settings.py
. Django will no longer load the app.
如果您不再希望应用程序的文件挂起,请从您的项目目录或其他位置删除应用程序目录PYTHONPATH它所在的位置。
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.
喜欢这样。
from django.contrib.contenttypes.models import ContentType
for c in ContentType.objects.all():
if not c.model_class():
print "deleting %s"%c
c.delete()
这篇关于Django:如何彻底卸载Django应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!