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-12-16
Python列表对象实现原理
2018-09-27
关于Python包和模块的10个知识清单
2014-03-26
斐波那契数列(Fibonacci)递归与非递归的性能对比
2017-08-01
Python 2 和 Python 3 主要区别有哪些(一)?
2019-05-13
python3判断list是否为空
2017-11-08
Python每日一题:第4题:用Python实现斐波那契数列
2019-04-09
Python中如何合并两个字典
2015-11-25
OS X El-Capitan 安装 virtualenvwrapper 遇到 Operation not permitted
2016-12-07
好玩的Python彩蛋
2018-10-15
提升逼格的两个函数:setdefault 与 defaultdict