您想使用 filter() 允许 != 的方法:seats = Seat.query.filter(Seat.invite != None).all()I can query my Seat table for all seats where there is no invite assigned:seats = Seat.query.filter_by(invite=None).all()However, when querying for all seats that have an invite assigned, I get a NameError:seats = Seat.query.filter_by(invite!=None).all()NameError: name 'invite' is not definedHere is my Seat class:class Seat(db.Model): id = db.Column(db.Integer, primary_key=True) invite_id = db.Column(db.Integer, db.ForeignKey('invite.id')) invite = db.relationship('Invite', backref=db.backref('folks', lazy='dynamic'))How can I query for all seats where the owner is not blank? 解决方案 The filter_by() method takes a sequence of keyword arguments, so you always have to use = with it.You want to use the filter() method which allows for !=:seats = Seat.query.filter(Seat.invite != None).all() 这篇关于Flask SQLAlchemy 使用“不等于"查询列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-10 13:27