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

猜你喜欢

2019-04-25
命令行神器 Click 快速上手
2019-05-07
Python如何提取url中的参数
2014-02-17
Python多线程编程
2017-05-15
一步一步教你认识Python闭包
2013-10-30
Python“不为人知的”特性
2019-05-13
python3判断list是否为空
2017-08-01
Python 2 和 Python 3 主要区别有哪些(一)?
2019-02-22
Python不行了?
2017-07-19
如何正确理解@classmethod与@staticmethod
2017-12-26
5个酷毙的Python工具