這個錯誤是因爲db.session.add()添加的參數必須爲對應的對象。不然會報錯sql
例如:
錯誤json
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'})
正確flask
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'})