尝试使用非主键的新信息更新行后发生sqlalchemy完整性错误

hjqgdpho  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(125)

我正在制作一个网站,其中一个可以提交一个编码提示,供其他人尝试。但是,我想添加更新提交的功能,以便到目前为止,我的代码是

function = form.function.data
func_call = function[function.index('def') + 4: function.index(':')]
func_name = func_call[:func_call.index("(")]

param = {
    "function": function,
    "testCaseInputs": form.testCaseInputs.data,
    "testCaseOutputs": form.testCaseOutputs.data,
}

try:
    Problem.query.filter_by(func_name = func_name).first().update(param)
    db.session.commit()

except exc.SQLAlchemyError as e:
    db.session.rollback()
    traceback.print_exc()

finally:
    db.session.remove()

当我尝试提交它时,会出现以下错误:sqlite3.integrityerror:unique constraint failed:problem.func\u name
但我不知道为什么,因为我甚至没有更新主键(func_name)。我对update(param)的理解是,update将使用我的字典,然后只更新那些列。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题