. Advertisement .
. Advertisement .
When you are trying to add more columns to a table, this annoying message will sometimes pop up: “Column count doesn’t match value count at row 1“. How to tackle this issue most tactically and efficiently? Check out our guidelines for more pointers!
Why Does This Error Occur?
If you activate an “Insert” statement, sometimes, the MySQL response to Column might not match the value count on row 1. Such errors occur when there is a palpable inequality between the table and the value quantity you aim to add to that table.
Let’s look at this example. Suppose we establish a pet table with all columns like this:
+----+----------+---------+------+ | id | owner | species | age | +----+----------+---------+------+ | 1 | Cristian | Parrot | 3 | | 2 | Micheal | Mouse | 5 | | 3 | David | Rabbit | 4 | | 4 | Harry | Cat | 2 | | 5 | Tom | Turtle | 4 | | 6 | Kevin | Hamster | 3 | +----+----------+---------+------+
What if we wish to add new rows to that pet table? Then values are required for all columns. Otherwise, the system will yield the “Column count doesn’t match value count” message.
Our “Insert” statement below only generates one single value for the whole table:
INSERT INTO pets VALUES("Frank");
However, MySQL needs four values for four columns. That is why the system triggers an error:
ERROR 1136 (21S01): Column count doesn’t match value count at row 1
How to Fix The “Column Count Doesn’t Match Value Count At Row 1” Error?
How to resolve the “Column count doesn’t match value count at row 1” issues? First, ensure that all the table columns – or the “Insert” statement – have matched the inserting values (To check whether your input is an integer, refer to this article.)
One of the most plausible methods is to spell out every chosen column in the “Insert” statement, verifying that each value clause matches your column list.
This example may help clear some clouds. It spells out the values and all column names:
INSERT INTO product_test (id, product_name) VALUES (1, 'Office Chair');
Such operations will add two values you wish to insert, ensuring all your right columns are employed (product_name and id). In other cases, it is also possible to spell out every column and its assigned value:
INSERT INTO product_test (id, product_name, price) VALUES (1, 'Office Chair', 100);
Three mentioned columns (price, product_name, id) and three mentioned values (100, ‘Office Chair’, 1) are transparent. So once you run these codes, they will successfully yield the right results! It is viable to extract column names from your “Insert” statement. Instead, you might operate this:
INSERT INTO product_test VALUES (1, 'Office Chair', 100);
This strategy will be effective, though it is a bit risky. After all, the column orders can easily alter once more columns are inserted. In those scenarios, the statement will break.
This article has shown you how to fix the annoying error, “Column count doesn’t match value count at row 1“. To avoid this error in your next programming endeavors, make sure to check that the number of columns and values are identical.
Good luck with your programming, and write to us if you still need more instructions!