[英]Could not process parameters: int(1), it must be of type list, tuple or dict
I am currently trying to insert two numbers into a column called konto_type_kode from a table called kontotype but i keep getting this error, here is what my code looks like:我目前正在尝试从名为 kontotype 的表中将两个数字插入名为 konto_type_kode 的列中,但我不断收到此错误,这是我的代码的样子:
import createdb
import createtables
import mysql.connector
config = mysql.connector.connect(
host = "localhost",
user = "root",
password = "root",
database = "dbank_banksystem"
)
cursor = config.cursor()
addtype1 = """ INSERT INTO kontotype (konto_type_kode) VALUES (%i, %i)"""
addtype1val = (1,2)
cursor.executemany(addtype1,addtype1val)
config.commit()
Placeholders in mysql-connector are %s
, not %i
. mysql-connector 中的占位符是%s
,而不是%i
。
cursor.executemany()
requires the parameters to be a 2-dimensional sequence, a sequence of rows to add. cursor.executemany()
要求参数是二维序列,即要添加的行序列。 So change addtype1val
to be a tuple of tuples.所以将addtype1val
更改为元组的元组。
You should only have one placeholder in the VALUES
list, since you're only inserting into one column.您应该在VALUES
列表中只有一个占位符,因为您只插入一列。 cursor.executemany()
will repeat the VALUES
list enough times for each row. cursor.executemany()
将为每一行重复VALUES
列表足够的次数。
addtype1val = ((1,), (2,))
addtype1 = """ INSERT INTO kontotype (konto_type_kode) VALUES (%s)"""
addtype1val = (1,2)
cursor.executemany(addtype1,addtype1val)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.