简体   繁体   中英

MongoEngine won't save default False value

I have defined a User model and added a featured field to it:

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. When I set it to True in model or when create the user, it creates it and saves proper True value to it. I want this field to be always present on creation if it's False or 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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