UnmappedInstanceError: Class 'flask_sqlalchemy.BaseQuery' is not mapped(Flask)
这个错误是由于db.session.add()添加的参数必须为对应的对象。否则会报错
例如:
错误
valuation_id = request.args.get('valuation_id')
valuation_sys = Valuation_sys.query.filter_by(id=valuation_id)
if valuation_sys is not None:
valuation_sys.delete_flag = 1
db.session.add(valuation_sys)
return jsonify({'code': '200', 'msg': 'delete success'})
else:
return jsonify({'code': '10000', 'msg': 'valuation id is not exist'})
正确
valuation_id = request.args.get('valuation_id')
valuation_sys = Valuation_sys.query.filter_by(id=valuation_id).first()
if valuation_sys is not None:
valuation_sys.delete_flag = 1
db.session.add(valuation_sys)
return jsonify({'code': '200', 'msg': 'delete success'})
else:
return jsonify({'code': '10000', 'msg': 'valuation id is not exist'})