简体   繁体   English

MongoEngine不会保存默认的False值

[英]MongoEngine won't save default False value

I have defined a User model and added a featured field to it: 我已经定义了一个用户模型,并向其中添加了一个featured字段:

class User(Document):
    email = EmailField(required=True)
    featured = BooleanField(default=False, required=True)

Then I create a user from this model and save it: 然后,我从该模型创建一个用户并将其保存:

user = User(email=email, featured=False)
user.save()

But even having a default value and required flag I don't see that field created in the db if the BooleanField is set to False. 但是,即使具有默认值和必需标志,但如果BooleanField设置为False,我也看不到该字段在db中创建。 When I set it to True in model or when create the user, it creates it and saves proper True value to it. 当我在模型中将其设置为True或创建用户时,它会创建它并为其保存适当的True值。 I want this field to be always present on creation if it's False or True. 我希望此字段在创建时始终为False或True。 What am I doing wrong? 我究竟做错了什么?

What version are you running? 您正在运行什么版本? We have a passing test case for this very issue: 对于这个问题,我们有一个通过测试用例:

See: https://github.com/MongoEngine/mongoengine/blob/master/tests/test_document.py#L2881-2893 参见: https : //github.com/MongoEngine/mongoengine/blob/master/tests/test_document.py#L2881-2893

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM