我使用的是Python3和SQLite3。我有一个包含6列的表,但我只在4列中插入值。
执行(“INSERT INTO VALUES(?,?,?,?)”,[list_name])
我得到的错误: 错误:表blacklisted_ips有6列,但提供了4个值
list_name = [(24,'somestring','2018/05/06','2018-05-13 10:16:34'),(24,'somestring','2018/05/06', '2018-05-13 10:16:34')]
所以问题是如何只写4个列?
答案 0 :(得分:1)
The SQLite page for INSERT operation指定:
If a column-name list is specified, then the number of values in each
term of the VALUE list must match the number of specified columns.
Each of the named columns of the new row is populated with the
results of evaluating the corresponding VALUES expression.
你想要的是:
INSERT INTO blacklisted_ips (col1, col2, col3, col4) VALUES (?, ?, ?, ?)