SQLAlchemy update 报错

By 刘志军 , 2019-06-13, 分类: qa

python

更新语句是这样的:

python result = Doctor.query\ .filter(Doctor.department_id==department_id) \ .filter(Doctor.id.in_(tuple(doctor_ids))) \ .update({"department_id":None}) 执行的时候报错

sqlalchemy.exc.InvalidRequestError: Could not evaluate current criteria in Python: "Cannot evaluate clauselist with operator ". Specify 'fetch' or False for the synchronize_session parameter. Traceback (most recent call last):

解决方法是:

result = Doctor.query\
            .filter(Doctor.department_id==department_id) \
            .filter(Doctor.id.in_(tuple(doctor_ids))) \
            .update({"department_id":None}, synchronize_session='fetch')

关注公众号「Python之禅」,回复「1024」免费获取Python资源

python之禅

猜你喜欢

2015-06-17
如何在Python中正确使用static、class、abstract方法
2020-06-13
python 中 xml 转换为 json
2017-12-26
5个酷毙的Python工具
2020-06-01
最新抖音去水印解析
2017-05-15
一步一步教你认识Python闭包
2022-03-13
从一段小代码开始学习如何重构
2013-10-30
Python“不为人知的”特性
2020-06-04
如何用Python执行linux命令
2020-06-07
python合并两个字典
2019-03-09
30个Python 小例子,帮你快速上手Python