gpt4 book ai didi

python - mongoengine : ReferenceFields will default to using ObjectId 中的问题

转载 作者:太空宇宙 更新时间:2023-11-04 09:12:44 27 4
gpt4 key购买 nike

关注这位官方tutorial我已经编码了:

#! /usr/bin/env python

from mongoengine import *

connect('tumbleblog')


class User(Document):
email = StringField(required=True)
first_name = StringField(max_length=50)
last_name = StringField(max_length=50)

class Comment(EmbeddedDocument):
content = StringField()
name = StringField(max_length=120)

class Post(Document):
title = StringField(max_length=120, required=True)
author = ReferenceField(User, reverse_delete_rule=CASCADE)
tags = ListField(StringField(max_length=30))
comments = ListField(EmbeddedDocumentField(Comment))

class TextPost(Post):
content = StringField()

class ImagePost(Post):
image_path = StringField()

class LinkPost(Post):
link_url = StringField()


john = User(email="example@gmail.com",first_name='john', last_name='doe')
john.save()

但我不知道为什么在尝试运行它时它说:

/Library/Python/2.7/site-packages/mongoengine/fields.py:736: FutureWarning: ReferenceFields will default to using ObjectId  strings in 0.8, set DBRef=True if this isn't desired
warnings.warn(msg, FutureWarning)
/Library/Python/2.7/site-packages/mongoengine/base.py:589: FutureWarning: TextPost uses inheritance, the default for allow_inheritance is changing to off by default. Please add it to the document meta.
FutureWarning
/Library/Python/2.7/site-packages/mongoengine/base.py:589: FutureWarning: ImagePost uses inheritance, the default for allow_inheritance is changing to off by default. Please add it to the document meta.
FutureWarning
/Library/Python/2.7/site-packages/mongoengine/base.py:589: FutureWarning: LinkPost uses inheritance, the default for allow_inheritance is changing to off by default. Please add it to the document meta.
FutureWarning
[Finished in 0.2s]

我哪里错了?我已经按照官方教程学习了。我是不是错过了什么?

附言Mongodb 启动并运行

最佳答案

future 的警告会提醒您 MongoEngine future 版本的变化,在您升级之前需要解决这些变化。

警告是:

ReferenceFields will default to using ObjectId strings in 0.8, set DBRef=True if this isn't desired

这意味着 - 如果您不想更改和迁移您的数据,您应该将定义更改为:

ReferenceField(User, dbref=False)  # Uses the original way of storing dbrefs
ReferenceField(User, dbref=True) # Uses a simpler way of storing dbrefs

关于python - mongoengine : ReferenceFields will default to using ObjectId 中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13219461/

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