使用 SQLAlchemy 删除寄存器时出现错误

问题描述 投票:0回答:1

我正在从与 SQLAlchemy 连接的数据库中删除一行,但收到以下错误:

File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
2020-06-12T20:37:21.822757+00:00 app[web.1]:     raise exception
2020-06-12T20:37:21.822873+00:00 app[web.1]: sqlalchemy.orm.exc.UnmappedInstanceError: Class 'builtins.NoneType' is not mapped

奇怪的是,我已经能够在另一张桌子上使用完全相同的问题,而且效果很好。

这是我的Python代码:

@app.route('/deleteleads/<solicitudes_id>/', methods=['GET', 'POST'])
def deleteleads(solicitudes_id):
    my_data = Data.query.get(solicitudes_id)
    db.session.delete(my_data)
    db.session.commit()
    flash("¡Lead eliminado satisfactoriamente!")

    return redirect(url_for('show_leads'))

这是我的模型:

class Leads(db.Model):
    __tablename__ = 'solicitudes'
    solicitudes_id = db.Column(db.BIGINT, primary_key=True)
    tipouso = db.Column(db.VARCHAR(255))
    tipoauto = db.Column(db.VARCHAR(255))
    credito = db.Column(db.BOOLEAN)
    entidadcrediticia = db.Column(db.VARCHAR(255))
    id_auto = db.Column(db.VARCHAR(255), db.ForeignKey('autos.id_auto'))
    id_user = db.Column(db.BIGINT, db.ForeignKey('usuarios.id_user'))
    fecha = db.Column(db.DATE)
    canalinput = db.Column(db.VARCHAR(255))
    ciudadcompra = db.Column(db.VARCHAR(255))
    hora = db.Column(db.TIME(255))


    def __init__(self, solicitudes_id, tipouso, tipoauto, credito, entidadcrediticia, id_auto, id_user, fecha, canalinput, ciudadcompra, hora):
        self.solicitudes_id = solicitudes_id
        self.tipouso = tipouso
        self.tipoauto = tipoauto
        self.credito = credito
        self.entidadcrediticia = entidadcrediticia
        self.id_auto = id_auto
        self.id_user = id_user
        self.fecha = fecha
        self.canalinput = canalinput
        self.ciudadcompra = ciudadcompra
        self.hora = hora
python postgresql flask sqlalchemy flask-sqlalchemy
1个回答
0
投票

问题是我没有使用正确的表格:

def deleteleads(solicitudes_id):
    my_data = Leads.query.get(solicitudes_id)
    db.session.delete(my_data)
    db.session.commit()
    flash("¡Lead eliminado satisfactoriamente!")

    return redirect(url_for('show_leads'))```
My table is Leads in this case, not Data.
© www.soinside.com 2019 - 2024. All rights reserved.