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-02-22
Python不行了?
2019-05-07
Python如何提取url中的参数
2020-06-01
最新抖音去水印解析
2017-11-18
What the fuck Python
2020-06-07
python合并两个字典
2020-06-14
python中如何将字符串转换为整数
2017-07-19
如何正确理解@classmethod与@staticmethod
2020-06-13
python 中 xml 转换为 json
2017-11-22
Python每日一题:第6题:如何设计一个代码统计工具
2020-06-13
检查对象中是否存在某个属性