MySQL 列数与第 1 行的值数不匹配
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18369252/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Column count doesn't match value count at row 1
提问by user2705462
So I read the other posts but this question is unique. So this SQL dump file has this as the last entry.
所以我阅读了其他帖子,但这个问题是独一无二的。所以这个 SQL 转储文件将此作为最后一个条目。
INSERT INTO `wp_posts` VALUES(2781, 3, '2013-01-04 17:24:19', '2013-01-05 00:24:19'.
I'm trying to insert this value to the table...
我正在尝试将此值插入表中...
INSERT INTO `wp_posts` VALUES(5, 5, '2005-04-11 09:54:35', '2005-04-11 17:54:35'
it gives me the error, "Column count doesn't match value count at row 1." So I'm lost on the concept of how the column and row apply here.
它给了我错误,“列数与第 1 行的值数不匹配。” 所以我对列和行如何在这里应用的概念迷失了方向。
Doesn't 2781,3
mean row 2781 and column 3? And doesn't 5,5
mean row 5 and column 5?
不是2781,3
说第 2781 行和第 3 列吗?并不5,5
意味着第 5 行和第 5 列?
回答by juergen d
The error means that you are providing not as much data as the table wp_posts
does contain columns. And now the DB engine does not know in which columns to put your data.
该错误意味着您提供的数据不如表wp_posts
中包含的列多。现在数据库引擎不知道将数据放在哪些列中。
To overcome this you must provide the names of the columns you want to fill. Example:
为了克服这个问题,您必须提供要填充的列的名称。例子:
insert into wp_posts (column_name1, column_name2)
values (1, 3)
Look up the table definition and see which columns you want to fill.
查找表定义并查看要填充的列。
And insert
means you are inserting a newrecord. You are not modifying an existing one. Use update
for that.
并且insert
意味着您正在插入新记录。您不是在修改现有的。update
为此使用。
回答by V Kash Singh
- you missed the comma between two values or column name
- you put extra values or an extra column name
- 您错过了两个值或列名之间的逗号
- 你放了额外的值或额外的列名
回答by inanutshellus
You should also look at new triggers.
您还应该查看新的触发器。
MySQL doesn't show the table name in the error, so you're really left in a lurch. Here's a working example:
MySQL 没有在错误中显示表名,所以你真的陷入了困境。这是一个工作示例:
use test;
create table blah (id int primary key AUTO_INCREMENT, data varchar(100));
create table audit_blah (audit_id int primary key AUTO_INCREMENT, action enum('INSERT','UPDATE','DELETE'), id int, data varchar(100) null);
insert into audit_blah(action, id, data) values ('INSERT', 1, 'a');
select * from blah;
select * from audit_blah;
truncate table audit_blah;
delimiter //
/* I've commented out "id" below, so the insert fails with an ambiguous error: */
create trigger ai_blah after insert on blah for each row
begin
insert into audit_blah (action, /*id,*/ data) values ('INSERT', /*NEW.id,*/ NEW.data);
end;//
/* This insert is valid, but you'll get an exception from the trigger: */
insert into blah (data) values ('data1');
回答by Sebastian
MySQL will also report "Column count doesn't match value count at row 1" if you try to insert multiple rows without delimiting the row sets in the VALUES section with parentheses, like so:
如果您尝试插入多行而不用括号分隔 VALUES 部分中的行集,MySQL 还将报告“列计数与第 1 行的值计数不匹配”,如下所示:
INSERT INTO `receiving_table`
(id,
first_name,
last_name)
VALUES
(1002,'Charles','Babbage'),
(1003,'George', 'Boole'),
(1001,'Donald','Chamberlin'),
(1004,'Alan','Turing'),
(1005,'My','Widenius');
回答by Devindu Dharmadasa
You can resolve the error by providing the column names you are affecting.
您可以通过提供您影响的列名称来解决错误。
> INSERT INTO table_name (column1,column2,column3)
`VALUES(50,'Jon Snow','Eye');`
please note that the semi colon should be added only after the statement providing values
请注意,分号只能在提供值的语句之后添加