我有 python 脚本,想要将数据插入数据库,如下所示:
(1, -0.12301105260848999)
(1, 0.07728659361600876)
(1, 0.005048183258622885)
(1, -0.03252531960606575)
(1, -0.05449267476797104)
(1, -0.026811596006155014)
(1, 0.014027083292603493)
(1, -0.10952591896057129)
(1, 0.15669232606887817)
(1, -0.04698480665683746)
(1, 0.26182907819747925)
(1, -0.015784427523612976)
Run Code Online (Sandbox Code Playgroud)
在该图中,我尝试手动将数据插入数据库,并且工作正常。但在我的 python 脚本中返回错误:
Failed processing format-parameters; Python 'float64' cannot be converted to a MySQL type
Run Code Online (Sandbox Code Playgroud)
我不知道这有什么问题,因为我手动插入并工作。我使用普通脚本插入数据库,这里是我的脚本:
insert_encode_query = """INSERT INTO encoding_data
(id, face_encode)
VALUES (%s, %s)"""
cursor = connection.cursor()
cursor.executemany(insert_encode_query, detail_encoding)
connection.commit()
Run Code Online (Sandbox Code Playgroud)
内部变量detail_encoding:
[(1, -0.12301105260848999), (1, 0.07728659361600876), (1, 0.005048183258622885), (1, -0.03252531960606575), (1, -0.05449267476797104), (1, -0.026811596006155014)]
Run Code Online (Sandbox Code Playgroud)
我的代码有什么问题,或者如何从 python float64 转换为浮点/小数的 SQL 类型,或者有任何解决方案吗?谢谢