我有一个类:
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”。事实上:
见下文:
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/