Django:更改模型中的字段类型时出现 FieldDoesNotExist 错误
Django: Got FieldDoesNotExist error when changing field type in models
我对 models.py
进行了更改。我将字段从 FileField()
更改为 ImageWithThumbsField()
from mongoengine import *
from gradfounder.settings import DBNAME
from embed_video.fields import EmbedVideoField
from thumbs import ImageWithThumbsField
##########################################
# Mongoengine registration/authentication
#from mongoengine.django.auth import User
##########################################
#connect(DBNAME)
# connect(DBNAME, host='127.0.0.1', port=27017)
connect(DBNAME, host='xxx.xxx.xxx.xxx', port=27017)
class Author(Document):
# photo = FileField()
photo = ImageWithThumbsField(upload_to="avatars")
photoname = StringField()
然后我得到这个错误
File "C:\Python27\lib\site-packages\mongoengine\base\document.py", line 80, in
__init__
raise FieldDoesNotExist(msg)
FieldDoesNotExist: The field 'photo' does not exist on the document 'Author'
我尝试迁移 syncdb
但出现错误 DatabaseError: (1050, "Table 'profiles_profile' already exists")
欢迎任何想一起解决这个问题的人。
是的!我找到了解决方案!
该错误是由于 Mongoengine 验证对更改的字段感到困惑而导致的。解决方案是通过添加此代码来禁用验证:
class Author(Document):
# photo = FileField()
photo = ImageWithThumbsField(upload_to="avatars")
photoname = StringField()
meta = {'strict': False}
感谢这个问题!
我对 models.py
进行了更改。我将字段从 FileField()
更改为 ImageWithThumbsField()
from mongoengine import *
from gradfounder.settings import DBNAME
from embed_video.fields import EmbedVideoField
from thumbs import ImageWithThumbsField
##########################################
# Mongoengine registration/authentication
#from mongoengine.django.auth import User
##########################################
#connect(DBNAME)
# connect(DBNAME, host='127.0.0.1', port=27017)
connect(DBNAME, host='xxx.xxx.xxx.xxx', port=27017)
class Author(Document):
# photo = FileField()
photo = ImageWithThumbsField(upload_to="avatars")
photoname = StringField()
然后我得到这个错误
File "C:\Python27\lib\site-packages\mongoengine\base\document.py", line 80, in
__init__
raise FieldDoesNotExist(msg)
FieldDoesNotExist: The field 'photo' does not exist on the document 'Author'
我尝试迁移 syncdb
但出现错误 DatabaseError: (1050, "Table 'profiles_profile' already exists")
欢迎任何想一起解决这个问题的人。
是的!我找到了解决方案!
该错误是由于 Mongoengine 验证对更改的字段感到困惑而导致的。解决方案是通过添加此代码来禁用验证:
class Author(Document):
# photo = FileField()
photo = ImageWithThumbsField(upload_to="avatars")
photoname = StringField()
meta = {'strict': False}
感谢这个问题!