- Fix “ERROR 1136 (21S01): Column count doesn’t match value count at row 1” when Inserting Data in MySQL
- Example of Error
- Solution 1
- Solution 2
- Error 1136 — Column count doesn’t match value count at row 1
- To fix this
- MySQL — How to fix the Column count doesn’t match value count at row 1 error
- Level up your programming skills
- Azure SQL Edge (16)
- Database Concepts (48)
- Database Tools (70)
- DBMS (8)
- MariaDB (420)
- Microsoft Access (17)
- MongoDB (265)
- MySQL (375)
- NoSQL (7)
- Oracle (296)
- PostgreSQL (255)
- Redis (184)
- SQL (588)
- SQL Server (887)
- SQLite (235)
Fix “ERROR 1136 (21S01): Column count doesn’t match value count at row 1” when Inserting Data in MySQL
One of the more common error message in MySQL goes like this: “ERROR 1136 (21S01): Column count doesn’t match value count at row 1“.
This error typically occurs when you’re trying to insert data into a table, but the number of columns that you’re trying to insert don’t match the number of columns in the table.
In other words, you’re either trying to insert too many columns, or not enough columns.
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.
The error can also occur if you pass the wrong number of columns to a ROW() clause when using the VALUES statement.
Example of Error
Suppose we have the following table:
The following code will cause the error:
In this case, I tried to insert data for four columns into a table that only has three columns.
We’ll get the same error if we try to insert too few columns:
The obvious solution is to insert the correct number of rows. Therefore, we could rewrite our code as follows:
Another way of doing it is to explicitly name the columns for which we want to insert data. This technique can be used to insert less columns than are in the table.
This method may result in a different error if there are any constraints that require a value to be passed for that column (for example, if the table has a NOT NULL constraint on that column). Therefore, you’ll need to ensure you’re complying with any constraints on the column when doing this.
Error 1136 — Column count doesn’t match value count at row 1
September 13, 2019
When trying to insert a new data row into a table, you might run into this error:
That error message typically means the number of values provided in the INSERT statement is bigger or smaller than the number of columns the table has, while at the same time, you did not specify the columns to be inserted. So MySQL doesn’t know which data to insert in which column and it throws back the error.
For example, you have this table employees :
And you try to insert a new data rows into that table with this INSERT statement:
As you can see, there are 7 columns in the table employees but you are providing only 6 values in the INSERT statement. MySQL returns the error:
To fix this
1. Provided the full required data
If you omit the column names when inserting data, make sure to provide a full row of data that matches the number of columns
Or if the email field is empty:
2. Specify the columns to be inserted in case not all columns are going to have value.
Sometimes, all the values are provided but you still see this error, you likely forgot to use the delimiter between two particular values and make it appear as one value. So double-check the delimiter and make sure you did not miss any semicolon.
Need a good GUI tool for databases? TablePlus provides a native client that allows you to access and manage Oracle, MySQL, SQL Server, PostgreSQL, and many other databases simultaneously using an intuitive and powerful graphical interface.
MySQL — How to fix the Column count doesn’t match value count at row 1 error
Last Updated Jul 03, 2022
Learn how to fix the Column count doesn’t match value count at row 1 MySQL error 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:
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:
But since MySQL requires 4 values for each column, the error gets triggered:
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:
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:
You can put as many column names as you need inside the parentheses.
Here’s another example of inserting data into three columns:
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:
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! 👍
Level up your programming skills
I’m sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I’ll send new stuff straight into your inbox!
Nathan Sebhastian is a software engineer with a passion for writing tech tutorials.