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

猜你喜欢

2020-06-14
python判断字典是否存在key
2019-03-09
30个Python 小例子,帮你快速上手Python
2015-12-10
Python字符串对象实现原理
2016-01-21
Python中的垃圾回收机制
2020-06-07
python合并两个字典
2016-09-18
分析urllib.unquote乱码的原因
2017-10-24
自学Python编程怎么学才不那么孤独
2017-10-29
Python每日一题:第1题
2019-05-12
Python时间戳转日期时间
2020-06-04
Python中global的用法