我在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")
欢迎任何想要共同努力的人。
答案 0 :(得分:3)
是的!我找到了解决方案!
错误是由Mongoengine验证造成的,他们对变化的字段感到困惑。解决方案是通过添加以下代码来禁用验证:
class Author(Document):
# photo = FileField()
photo = ImageWithThumbsField(upload_to="avatars")
photoname = StringField()
meta = {'strict': False}
感谢这个问题! mongoengine - Ignore extra fields for schema validation