2016-09-16 476 views
0

我在我的django项目上安装了一个新的应用程序(社交)。如何在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中包含社交时,我只会收到此错误消息。

+1

您的数据库在这一点上并不重要。引发异常是因为代码中的某个位置已定义此模型类。删除它,你会没事的。 –

回答

0

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

之后,您只需要从该应用程序中取消所有迁移即可。

所以运行此命令

./manage.py migrate social zero 

因此,这将撤消所有命名社交应用程序中所做的迁移

+0

这给了我以下** app = models.get_app(app_label) 文件“/home/paco/.virtualenvs/analytics_env/local/lib/python2.7/site-packages/django/db/models/loading.py “,第152行,在get_app raise raiselyconfigured(”无法找到带有标签%s的应用程序“%app_label) django.core.exceptions.ImproperlyConfigured:无法找到带有社交标签的应用** – user3007270

0

原来我创建了一个models.py文件。然后我删除了该文件,但models.pyc保留在文件夹中。我的IDE没有显示它,但它在那里。删除.pyc为我解决了它。多谢你们!