Column count doesn t match value count at row 1 как исправить

So I read the other posts but this question is unique. So this SQL dump file has this as the last entry. INSERT INTO `wp_posts` VALUES(2781, 3, '2013-01-04 17:24:19', '2013-01-05 00:24:19'. I'm t...

So I read the other posts but this question is unique. So this SQL dump file has this as the last entry.

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.

Doesn’t 2781,3 mean row 2781 and column 3? And doesn’t 5,5 mean row 5 and column 5?

Ferdinand.kraft's user avatar

asked Aug 21, 2013 at 23:26

user2705462's user avatar

1

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.

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 new record. You are not modifying an existing one. Use update for that.

answered Aug 21, 2013 at 23:29

juergen d's user avatar

juergen djuergen d

199k36 gold badges286 silver badges350 bronze badges

  1. you missed the comma between two values or column name
  2. you put extra values or an extra column name

ycomp's user avatar

ycomp

8,05619 gold badges56 silver badges90 bronze badges

answered Jan 12, 2016 at 6:51

V Kash Singh's user avatar

0

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:

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');

answered Nov 10, 2016 at 17:09

inanutshellus's user avatar

inanutshellusinanutshellus

9,4039 gold badges52 silver badges71 bronze badges

4

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:

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');

Shaishav Jogani's user avatar

answered Jun 9, 2017 at 16:44

Sebastian's user avatar

SebastianSebastian

3652 silver badges13 bronze badges

1

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

answered Mar 9, 2019 at 23:08

Devindu Dharmadasa's user avatar

In my case i just passed the wrong name table, so mysql couldn’t find the right columns names.

answered May 20, 2022 at 7:03

Matteo Toma's user avatar

Matteo TomaMatteo Toma

4803 silver badges11 bronze badges

Photo from Unsplash

When you run an INSERT statement, you might see MySQL responding with Column count doesn't match value count at row 1 error.

This error occurs when the number of columns that your table has and the number of values you try to insert into the table is not equal.

For example, suppose you have a pets table with 4 columns as follows:

+----+--------+---------+------+
| id | owner  | species | age  |
+----+--------+---------+------+
|  1 | Jessie | bird    |    2 |
|  2 | Ann    | duck    |    3 |
|  3 | Joe    | horse   |    4 |
|  4 | Mark   | dog     |    4 |
|  5 | Ronald | cat     |    1 |
+----+--------+---------+------+

When you want to insert data into the pets table above, you need to provide values for all 4 columns, or you will trigger the column count doesn't match value count error:

The following INSERT statement only provides one value for the table:

INSERT INTO pets 
  VALUES("Jack");

But since MySQL requires 4 values for each column, the error gets triggered:

ERROR 1136 (21S01): Column count doesn't match value count at row 1

To resolve this error, you can either:

  • Provide values equal to the number of columns you have in your table
  • Or specify the column table you wish to insert values

Let’s learn how to do both.

First, you can specify the values for each column as in the following statement:

INSERT INTO pets 
  VALUES(NULL, "Jack", "duck", 2);

The above statement will work because the pets table has four columns and four values are provided in the statement.

But if you only have values for specific columns in your table, then you can specify the column name(s) that you want to insert into.

Here’s an example of inserting value only to the species column. Note that the column name is added inside parentheses after the table name:

INSERT INTO pets(`species`) 
  VALUES("panda");

You can put as many column names as you need inside the parentheses.

Here’s another example of inserting data into three columns:

INSERT INTO pets(`owner`, `species`, `age`) 
  VALUES("Bruce", "tiger", 5);

The id column is omitted in the example above.

Keep in mind that the same error will happen if you have more values to insert than the table columns.

Both statements below will return the error:

-- 👇 trying to insert five values
INSERT INTO pets 
  VALUES(NULL, "Jack", "duck", 2, TRUE);

-- 👇 trying to insert two values, but specify three columns
INSERT INTO pets(`owner`, `species`, `age`) 
  VALUES("Jane", "cat");

By default, MySQL will perform an INSERT statement expecting each column to have a new value.

When you specify the column names that you want to insert new values into, MySQL will follow your instructions and remove the default restrictions of inserting to all columns.

And those are the two ways you can fix the Column count doesn't match value count at row 1 error in MySQL database server.

I’ve also written several articles on fixing other MySQL errors. I’m leaving the links here in case you need help in the future:

  • Fix MySQL Failed to open file error 2
  • Fix MySQL skip grant tables error
  • Solve MySQL unknown column in field list error

And that’s it for column count doesn’t match value count error.

Thanks for reading! 👍

Перейти к содержимому

Однажды понадобилось очень быстро внести запись в таблицу и я быстро написал SQL запрос, но после его выполнения получил ошибку:

(21S01) Column count doesn’t match value count at row 1

Как оказалось, ошибка возникла из-за того, что я пропустил одно значение в SQL запросе, то есть количество столбцов в таблице не соответствовало количеству столбцов в моем SQL запросе.

Допустим у меня был не верный SQL запрос (для примера я специально привел простой SQL запрос и не указал значение для последнего столбца «groups»):

INSERT INTO table1 (id, key, methods, groups) VALUES ('', 'ixnfo.com', 4);

Потом я посмотрел структуру таблицы чтобы сверить столбцы:

SHOW CREATE TABLE table1;
DESC table1;

И исправил свой SQL запрос, указав значение для столбца groups — XXX, после этого SQL успешно выполнился:

INSERT INTO table1 (id, key, methods, groups) VALUES ('', 'ixnfo.com', 4, 'XXX');

SELECT * FROM extreceipts_kkt;

Смотрите другие мои статьи про MySQL

You may get tis value, if you are missing the value for auto_increment column. The error is as follows −

mysql> insert into DemoTable1353 values('Chris',23);
ERROR 1136 (21S01): Column count doesn't match value count at row 1

You need to provide the value for auto_increment or leave it to automatic generation.

Let us see an example and create a table −

mysql> create table DemoTable1353
    -> (
    -> Id int NOT NULL AUTO_INCREMENT,
    -> Name varchar(20),
    -> Age int,
    -> PRIMARY KEY(Id)
    -> );
Query OK, 0 rows affected (0.52 sec)

Insert some records in the table using insert command. We haven’t inserted auto increment value and it will generate on its own −

mysql> insert into DemoTable1353(Name,Age) values('Chris',23);
Query OK, 1 row affected (0.30 sec)
mysql> insert into DemoTable1353(Name,Age) values('David',21);
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable1353(Name,Age) values('Bob',24);
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable1353(Name,Age) values('John',47);
Query OK, 1 row affected (0.11 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1353;

This will produce the following output −

+----+-------+------+
| Id | Name  | Age  |
+----+-------+------+
|  1 | Chris |   23 |
|  2 | David |   21 |
|  3 | Bob   |   24 |
|  4 | John  |   47 |
+----+-------+------+
4 rows in set (0.00 sec)

Понравилась статья? Поделить с друзьями:
  • Collision prevention assist plus ошибка
  • Collision prevention assist plus не действует как убрать ошибку
  • Collection data error перевод
  • Collecting data error please check your signal телекарта
  • Collect2 fatal error ld terminated with signal 9 убито