【问题标题】:How can I delete a model in django?如何在 django 中删除模型?
【发布时间】:2016-09-16 21:37:52
【问题描述】:

我正在我的 django 项目上安装一个新的应用程序(社交)。

当我输入python manage.py runserver 0.0.0.0:8000 时出现以下错误

Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x971d56c>>
Traceback (most recent call last):
...
django.core.management.base.CommandError: One or more models did not validate:
social.socialall: "client_name": CharFields require a "max_length" 
attribute that is a positive integer.
social.socialall: "customer_name": CharFields require a "max_length" attribute that is a positive integer.
social.socialall: "publisher_id": CharFields require a "max_length" attribute that is a positive integer.
social.socialall: "currency": CharFields require a "max_length" attribute that is a positive integer.

不久前我创建了一个社交模型,但从未使用过它,因此将其从代码中删除。

我正试图找出social.socialall 这个住在哪里。我假设 django.db.models 但我正在查询我的 SQL 数据库并且找不到任何东西。

只有当我在 installed_apps 中包含社交时,我才会收到此错误消息。

【问题讨论】:

  • 此时您的数据库无关紧要。引发异常是因为您在代码中的某处定义了此模型类。删除它,你会没事的。

标签: django models


【解决方案1】:

确保它不在已安装的应用程序中。

之后您所要做的就是取消应用此应用程序中的所有迁移。

所以运行这个命令

./manage.py migrate social zero

因此,这将撤消在名为 social

的应用程序中进行的所有迁移

【讨论】:

  • 这给了我以下 app = models.get_app(app_label) File "/home/paco/.virtualenvs/analytics_env/local/lib/python2.7/site-packages/django/ db/models/loading.py",第 152 行,在 get_app raise ImproperlyConfigured("App with label %s could not be found" % app_label) django.core.exceptions.ImproperlyConfigured: App with label social can not be found
【解决方案2】:

原来我创建了一个 models.py 文件。然后我删除了该文件,但 models.pyc 仍保留在文件夹中。我的 IDE 没有显示它,但它就在那里。删除 .pyc 为我修复了它。谢谢各位!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-17
    • 1970-01-01
    • 2011-06-17
    • 2018-11-25
    • 1970-01-01
    • 2016-08-30
    相关资源
    最近更新 更多