Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Column count doesn't match value count at row" but it does

Tags:

mysql

count

I've got a mysql file with over than 14000 statements. All of them are inserts into a table, and when I import the file using console, it throws the following error:

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

I know that error appears when the rows specified in column names are different from the rows specified in VALUES list, but I've checked it out many times and the number of columns is exactly the same in both lists.

The row in position 45 is:

('00553', 'AAA', 'BBB', 'CCC', 'XXXXXXXXR', 'user address', 'spain', 'spain', '39212', '1900-01-21', '123456789', 'M', 'No disponible', 0, 'AAA', 'BBB ', 'CCC', 'XXXXXXXXR', NULL, '888993344', '', '', '', '', 'no', 'no') --> 26 columns

and the insert line associated with it, many lines above is:

INSERT INTO `users` (`id_patient`, `name`, `surname1`, `surname2`, `dni`, `address`, `city`, `state`, `postal_code`, `birthday`, `telephone`, `sex`, `email`, `lopd_status`, `lopd_name`, `lopd_surname1`, `lopd_surname2`, `lopd_dni`, `lopd_as`, `mobile_phone`, `notes`, `job`, `company`, `place`, `active_citation`, `signature`)  --> 26 columns

I've looked for this error but it seems it only appears when count is different, but in this case, it is the same.

Any idea?

EDIT: forgot to mention: if I throw the sql statement directly on phpmyadmin, it adds the line correctly without any errors. It only crashes when run from command line, although the statements above it are correctly inserted into database and they are almost the same than this one.

EDIT2: I've removed all lines until the 46 and when I launch the file the erros is the following:

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

It only changes the line, but that line is the INSERT statement, which is exactly the same as the other INSERT statements in the rest of the file. The previos line is also correct.

like image 233
Pask Avatar asked Oct 24 '12 07:10

Pask


People also ask

How to fix column count doesn t match value count at row 1?

To resolve this “Column count doesn't match value count at row 1” error, you have to ensure that the columns in the table or your INSERT statement match the values you are inserting. The best way to do this is to specify the columns you want in your INSERT statement and ensure the VALUES clause matches the column list.

How do I fix error 1136 in MySQL?

To fix this issue, make sure you're inserting the correct number of columns into the table. Alternatively, you can name the columns in your INSERT statement so that MySQL knows which columns your data needs to be inserted into.


2 Answers

I faced a similar problem because of inserting parenthesis around data :-(:

INSERT INTO Customers (Name,LastCredit,CreditDate) VALUES ( <-- Here.     ("Nuclear Millitary Systems",500.0,CURRENT_DATE),     ("Evil Corporation",67890.95,"2012-02-12"),     ("Nuke Software Systems",5600.0,"2013-05-06"),     ("RR Millitary",600.0,"2013-05-06"),     ("Random Automation",560.0,"2012-05-01"),     ("Evil Data Systems",600.0,"2013-03-01")   );  
like image 137
valplo Avatar answered Oct 13 '22 16:10

valplo


I was facing a similar error. It was just the matter of a missing comma. Check if all the items in the insert statement are separated by commas

like image 44
Dolly Avatar answered Oct 13 '22 15:10

Dolly