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

猜你喜欢

2016-12-07
好玩的Python彩蛋
2023-04-15
如何删除macOS系统默认的Python2.7并替换成最新版python3.11
2017-10-29
Python每日一题:第1题
2017-12-26
5个酷毙的Python工具
2020-12-25
PDF转换库 WeasyPrint 使用指南
2019-11-21
自己动手写个"狗屁不通"文章生成器
2014-02-10
python 函数式编程处理函数:map(),filter(),reduce()
2014-03-26
斐波那契数列(Fibonacci)递归与非递归的性能对比
2022-08-17
如何利用多态干掉 if else 语句
2017-07-19
如何正确理解@classmethod与@staticmethod