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

猜你喜欢

2017-09-01
关于操作 Python 列表最常见的10个问答
2017-12-26
5个酷毙的Python工具
2016-03-01
标签云算法Python实现
2020-06-04
如何用Python执行linux命令
2020-06-04
object is not subscriptable 是什么错误
2020-06-13
python 中 删除列表元素
2017-11-08
Python每日一题:第4题:用Python实现斐波那契数列
2017-10-22
图解Python变量与赋值
2020-06-04
Python中global的用法
2017-10-24
自学Python编程怎么学才不那么孤独