Flask-SQLAlchemy check if row exists in table

前端 未结 5 2059
耶瑟儿~
耶瑟儿~ 2020-12-05 02:17

I have a Flask application which uses Flask-SQLAlchemy to connect to a MySQL database.

I would like to be able to check whether a row is present in a table. How woul

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 02:48

    Think there is a typo in davidism's answer, this works for me:

    exists = db.session.query(**User**).filter_by(name='davidism').scalar() is not None
    

提交回复
热议问题