• 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'})
    
  • 相关阅读:
    模块
    Queue(队列)
    Stack(栈)
    Vector(容器)
    位图像素的颜色
    大数处理之三(除法)
    大数处理之二(幂运算)
    浮点数(double)的优势
    大数处理之一(加法和乘法)
    Depth-First Search
  • 原文地址:https://www.cnblogs.com/Zidon/p/5981611.html
Copyright © 2020-2023  润新知