简体   繁体   English

如何用Peewee做一个.where(somecolumn == None / Null / Empty)?

[英]How to do a .where(somecolumn == None/Null/Empty) with Peewee?

I'm using peewee in my Flask application and I have one column in a table which can be null: 我在我的Flask应用程序中使用了peewee,并且我在表中有一列可以为null:

somecolumn = ForeignKeyField(Something, related_name='messages', null = True, default=None)

I now want to select all records in which somecolumn is not null/None/Empty. 我现在想要选择somecolumn不为null / None / Empty的所有记录。 I tried to do this with the following: 我试着用以下方法做到这一点:

Message.select().where(Message.somecolumn != None)
Message.select().where(Message.somecolumn != '')

Unfortunately, neither works. 不幸的是,两者都无效 Does anybody know how I can do this? 有人知道我怎么做吗? All tips are welcome! 欢迎所有提示!

我不是一个peewee专家,但从文档( 查询 )看起来你需要:

Message.select().where(Message.somecolumn >> None)

It's a possibility: 这是一种可能性:

Message.select().where(Message.somecolumn.is_null(False))

Documentation 文档

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

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