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-09-05
Python:动态语言与鸭子类型
2020-10-30
WSGI 是什么,看完一定懂
2016-01-21
Python中的垃圾回收机制
2020-12-25
PDF转换库 WeasyPrint 使用指南
2020-05-07
Python挑战题
2016-12-07
好玩的Python彩蛋
2014-02-17
Python多线程编程
2019-02-22
Python不行了?
2020-06-14
python中如何将字符串转换为整数
2019-05-13
python3判断list是否为空