gpt4 book ai didi

python - MongoEngine fieldDoesNotExist错误,但实际上是

转载 作者:行者123 更新时间:2023-12-03 08:38:27 25 4
gpt4 key购买 nike

我有一个类:

class POI(Document):
location = PointField(required=True)
name = StringField(default='')
generate_by = IntField(required=True)
status = StringField(default='Active')
colleсted_by = IntField()
time_created = DateTimeField(default=datetime.datetime.now)
当我尝试插入
POI(location=[55.430212, 30.521000], generate_by=1241254, name="Sample", collected_by=None)
发生错误
mongoengine.errors.FieldDoesNotExist: The fields "{'collected_by'}" do not exist on the document "POI"
怎么了?

最佳答案

实际上,在两个“collected_by”字符串中有一个很小的错字,这使它们有所不同,由于某种原因,您在此处使用的“c”:

class POI(Document):
location = PointField(required=True)
name = StringField(default='')
generate_by = IntField(required=True)
status = StringField(default='Active')
colleсted_by = IntField()
^
|
不是常规的拉丁字母“c”,而是西里尔字母,看起来完全像拉丁字母“c”。
事实上:
  • 拉丁文“c”(https://www.codetable.net/decimal/99)
  • 西里尔字母“с”(https://www.codetable.net/decimal/1089)

  • 见下文:
    In [16]: "collected_by" == "colleсted_by"
    Out[16]: False

    In [17]: "с" == "c"
    Out[17]: False

    In [20]: ord("с"), ord("c")
    Out[20]: (1089, 99)
    如果您使它们相同,则代码将像 super 按钮一样工作

    关于python - MongoEngine fieldDoesNotExist错误,但实际上是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64404241/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com