在MySQL中插入记录时卡住[已关闭]

rvpgvaaj  于 2022-12-28  发布在  Mysql
关注(0)|答案(1)|浏览(118)

3小时前关门了。
Improve this question
在MySQL中插入记录时遇到此错误

json_object = json.dumps(all_params)
result = json_object[1:-1]
# comparison_df_final.to_sql(con=conn, name='tbl_alerts_master')
            
with conn.cursor() as cur:
    query = "INSERT INTO tbl_alerts_master (alert_name, alert_type_id, alert_details, resolved,     plant_id, machine_id) VALUES (%s, %s, %s, %s, %s, %s)" % ("Wheel Rejected", "3", result, False, "pna", "LPDC11")
    # value = ("Wheel Rejected", "3", json_object, False, "pna", "LPDC11")    
    rc = cur.execute(query) 
    print('RC', rc) 
conn.commit()

这是代码。其他一切工作,只是写作没有发生。请帮助。
这是我的 * json_object *:

{
  "to": 140,
  "from": 140,
  "name": "cooling.1.sp.delay"
}

我已尝试更改查询的值,但没有任何效果。

whlutmcx

whlutmcx1#

参数应按如下方式放置:

query = "INSERT INTO tbl_alerts_master (alert_name, alert_type_id, alert_details, resolved, plant_id, machine_id) VALUES (%s, %s, %s, %s, %s, %s)"

rc = cur.execute(query, ("Wheel Rejected", "3", result, False, "pna", "LPDC11"))

相关问题