(由指示@augurar)):因为
SQLAlchemy的 使用 魔术方法(操作符重载)
创建
SQL结构,但它只能处理操作,如
!=或
==,但不能与工作
is(这是一种非常有效的Python结构)。
因此,要使其与sqlalchemy一起使用,应使用:
...filter(or_(people.marriage_status!='married', people.marriage_status == None))
,基本上取代了
is None用
== None。在这种情况下,您的查询将被正确转换为以下SQL:
SELECt people.name AS people_name, people.marriage_status AS people_marriage_status FROM people WHERe people.marriage_status IS NULL OR people.marriage_status != ?
请参阅
ISNULL中的文档。



