【问题标题】:Django: Got FieldDoesNotExist error when changing field type in modelsDjango:更改模型中的字段类型时出现 FieldDoesNotExist 错误
【发布时间】:2016-10-13 06:25:45
【问题描述】:

我更改了我的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")

欢迎任何想要一起工作的人。

【问题讨论】:

    标签: python django django-models mongoengine django-file-upload


    【解决方案1】:

    是的!我找到了解决办法!

    这个错误是由 Mongoengine 验证引起的,他对更改的字段感到困惑。解决方案是通过添加以下代码来禁用验证:

    class Author(Document):
        # photo = FileField()
        photo = ImageWithThumbsField(upload_to="avatars")
        photoname = StringField()
        meta = {'strict': False}
    

    感谢这个问题! mongoengine - Ignore extra fields for schema validation

    【讨论】:

    • ImageWithThumbsField 使用哪个包?
    • 我用django-thumbs
    猜你喜欢
    • 1970-01-01
    • 2021-04-20
    • 2010-11-06
    • 2017-03-14
    • 2016-06-30
    • 1970-01-01
    • 2020-01-26
    • 1970-01-01
    • 2022-01-23
    相关资源
    最近更新 更多