2012-11-04 78 views
1

在此之後正式tutorial我編寫這樣的:問題mongoengine:ReferenceFields將默認使用的ObjectId

#! /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="[email protected]",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] 

我哪裏出錯了?我遵循官方教程..我錯過了什麼?

PS MongoDB是啓動和運行

+0

沒有什麼真正的'錯誤'。未來的警告是Python和其他語言中的一個常見習慣用法,以提醒您將會棄用的內容。 – Petri

回答

3

未來的警告是爲了提醒您在升級之前將需要尋址的未來版本的MongoEngine中的更改。

的警告是:

ReferenceFields將默認爲0.8使用的ObjectId字符串,設置DBREF = true如果不想這樣

它的意思是 - 如果你不想更改並遷移您的數據,您應該將定義更改爲:

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

離開DBRef的理由是什麼? – Mitar

+0

Space - ObjectId比DBRefs更受歡迎 – Ross