I'm using peewee in my Flask application and I have one column in a table which can be 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. 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!

有帮助吗?

解决方案

I'm not a peewee expert, but from the documentation (Querying) it looks like you need:

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

其他提示

It's a possibility:

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

Documentation

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top