UnmappedInstanceError: Class 'flask_sqlalchemy.BaseQuery' is not mapped


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'})


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM