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-07-01
Python是怎么火起来的
2019-05-12
Python时间戳转日期时间
2017-11-03
Python陷阱:为什么不能用可变对象作为默认参数的值
2014-03-26
斐波那契数列(Fibonacci)递归与非递归的性能对比
2015-12-16
Python列表对象实现原理
2019-05-16
命名难,难于上青天
2015-12-08
Python 整数对象实现原理
2017-11-03
Python每日一题:第3题:统计一个文件中每个单词出现的次数
2017-12-26
5个酷毙的Python工具
2015-11-25
OS X El-Capitan 安装 virtualenvwrapper 遇到 Operation not permitted