我一直在寻找这个错误的解决方案,但对于其他人来说,这似乎是由一个稍微不同的原因造成的。我有一个类似于以下内容的models.py:
class MyModel(models.Model):
something1 = models.IntegerField()
something2 = models.CharField(max_length=256)
something3 = models.CharField(max_length=256)
class MyModelForm(ModelForm):
class Meta:
model = MyModel
fields = ('something1', 'something2',)
说我实际上并不想使用' something3'了。如果我删除它,甚至删除并重新同步数据库,我会收到错误
为MyModel指定的未知字段(something3)。
据我所知,当我使用
保存任何内容时,会发生这种情况saveThis = MyModel(something1=x, something2=y)
saveThis.save()
任何想法是什么引发了这个错误?我甚至搜索了所有文件,以确保' something3'不在其中任何一个。这是追溯:
File "/Users/me/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/django/core/handlers/base.py", line 92, in get_response
response = middleware_method(request)
File "/Users/me/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/django/middleware/common.py", line 69, in process_request
if (not urlresolvers.is_valid_path(request.path_info, urlconf) and
File "/Users/me/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/django/core/urlresolvers.py", line 551, in is_valid_path
resolve(path, urlconf)
File "/Users/me/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/django/core/urlresolvers.py", line 440, in resolve
return get_resolver(urlconf).resolve(path)
File "/Users/me/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/django/core/urlresolvers.py", line 319, in resolve
for pattern in self.url_patterns:
File "/Users/me/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/django/core/urlresolvers.py", line 347, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/me/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/django/core/urlresolvers.py", line 342, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/Users/me/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/me/Sites/myproj/myproj/urls.py", line 2, in <module>
from myproj.views import myView1, myview2,...
File "/Users/me/Sites/myproj/myproj/views.py", line 4, in <module>
from mainapp.models import MyModel
File "/Users/me/Sites/myproj/myproj/mainapp/models.py", line 80, in <module>
class MyModelForm(ModelForm):
File "/Users/me/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/django/forms/models.py", line 221, in __new__
raise FieldError(message)
FieldError: Unknown field(s) (something3) specified for MyModel