Python 未知列'';在';字段列表'-关于在mySQL中插入对象
我正在尝试将数据列上传到mySQL数据库中。下面是遇到问题的代码片段Python 未知列'';在';字段列表'-关于在mySQL中插入对象,python,mysql,mariadb,Python,Mysql,Mariadb,我正在尝试将数据列上传到mySQL数据库中。下面是遇到问题的代码片段 cursor = mariadb_connection.cursor() cursor.execute=("CREATE TABLE IF NOT EXISTS table1 (ts TIMESTAMP, col2 char(10), col3 decimal (7,2), col4 decimal (5,2), col5 decimal (7,2), col6 decimal (5,2))") sql ="INSERT IN
cursor = mariadb_connection.cursor()
cursor.execute=("CREATE TABLE IF NOT EXISTS table1 (ts TIMESTAMP, col2 char(10), col3 decimal (7,2), col4 decimal (5,2), col5 decimal (7,2), col6 decimal (5,2))")
sql ="INSERT INTO table1 (ts, col2, col3, col4, col5, col6)"
sql += "VALUES (NULL, %s, %s, %s, %s, %s)"
cursor.execute(sql,(var2, var3, var4, var5, var6))
运行代码时,出现以下错误:
cursor.execute(sql,(var2,var3,var4,var5,var6))类型错误:“str”对象不可调用
请注意,var2
到var6
是从str
对象转换而来的decimal
对象
更新:从有问题的行中删除=
后,我现在似乎出现了另一个错误:mysql.connector.errors.ProgrammingError:1054(42S22):字段列表中的未知列“ts”。
你知道我做错了什么吗
更新:未知列问题的解决方案是删除现有表,然后再次运行脚本从
光标中删除=
符号。excecute=(…)
并使用此选项
cursor.execute("CREATE TABLE IF NOT EXISTS table1 (ts TIMESTAMP, col2 char(10), col3 decimal (7,2), col4 decimal (5,2), col5 decimal (7,2), col6 decimal (5,2))")
您在这些变量var2到var6中保存了什么?您已经用
cursor.execute=…
覆盖了execute
,谢谢。我现在似乎有另一个错误:mysql.connector.errors.ProgrammingError:1054(42S22):“字段列表”中的未知列“ts”
。但是,我已经指出这将是timestamp列。是否已创建表?如果已经创建,请查看此ts字段是否存在?谢谢,收到了!我删除了现有的表,然后再次运行脚本,现在运行良好。