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彩蛋
2017-12-05
用 Python 连接 MySQL 的几种姿势
2015-12-24
Python字典对象实现原理
2017-12-26
用 Python 处理 HTML 转义字符的5种方式
2017-08-01
Python 2 和 Python 3 主要区别有哪些(一)?
2017-07-19
如何正确理解@classmethod与@staticmethod
2017-03-15
Python 函数中,参数是传值,还是传引用?
2018-09-27
关于Python包和模块的10个知识清单
2017-12-26
5个酷毙的Python工具
2019-02-22
Python不行了?