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之禅

猜你喜欢

2020-06-04
如何对python字典进行排序
2020-06-14
python中文件复制
2019-05-13
python3判断list是否为空
2022-05-21
为啥用 PIP 安装库也会提示UnicodeDecodeError?
2019-05-12
一行代码将 cookie 字符串转换成字典对象
2020-05-07
Python自制PornHub风格的LOGO
2020-06-04
如何用Python执行linux命令
2017-07-19
如何正确理解@classmethod与@staticmethod
2022-03-13
从一段小代码开始学习如何重构
2020-12-25
PDF转换库 WeasyPrint 使用指南