【问题标题】:Trying to upload data from python to mysql, but the insertion is not commited尝试从python上传数据到mysql,但是插入没有提交
【发布时间】:2023-01-08 20:16:25
【问题描述】:

我正在尝试使用 django 和 mysql 将一些数据行从 python 上传到 mysql,因为我们还想在我们的网页中显示数据库中的数据。

与服务器的连接正常工作,与数据库的连接也是如此。

当我们执行以下查询将数据从 python 插入到 mysql 时,问题就来了。

def addInfo(请求,T,P,A,Rx,Ry,Rz,Ax,Ay,Az,Fecha,Long,Lat,Vel): """conexion = mysql.connector.connect(user='root', password='admin', host='localhost', 数据库='数据',端口='3306') 打印(连接) 游标 = conexion.cursor()

print("T:"+str(T))"""

query = "use datos; INSERT INTO datos(Temperatura, Presion, Altitud, RotacionX, RotacionY, RotacionZ, AceleracionX, AceleracionY, AceleracionZ, Fecha, Longitud, Latitud, Velocidad) VALUES ('"+T+"','"+P+"','"+A+"','"+Rx+"','"+Ry+"','"+Rz+"','"+Ax+"','"+Ay+"','"+Az+"','"+Fecha+"','"+Long+"', '"+Lat+"', '"+Vel+"');"

print(query)

cursor.execute(query)

documento = """<!DOCTYPE html>
<html>
<head>
--HTML PART IS OMITTED--
</html>"""
print(cursor)
cursor.close()
return HttpResponse(documento)

当我们执行这段代码时,数据库不会更新行,但是当我们在 mysql 中手动执行时,它确实有效并且 id 自动递增,就像我们上传了之前的查询一样。 (但上一行没有出现)

【问题讨论】:

    标签: python mysql django


    【解决方案1】:

    您正在将数据插入数据库,而不是将数据插入表。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-06
    • 2015-05-09
    • 2021-03-24
    • 2018-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-09
    相关资源
    最近更新 更多