Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL column count does not match value count error

Tags:

sql

mysql

I have this table:

CREATE TABLE `message` (
    `m_id` INT(11) NOT NULL AUTO_INCREMENT,
    `p_id` VARCHAR(30) NOT NULL,
    PRIMARY KEY (`m_id`)
)
ENGINE=InnoDB
ROW_FORMAT=DEFAULT

and this insert

INSERT INTO `message` VALUES ('7');

and I am receiving a "column count does not match a row value count" error. It should work fine since the primary key is auto_increment.

like image 203
Tower Avatar asked Apr 21 '11 15:04

Tower


People also ask

How do I fix the error for column count that 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?

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.

How do I count columns in SQL query?

mysql> SELECT COUNT(*) AS NUMBEROFCOLUMNS FROM INFORMATION_SCHEMA. COLUMNS -> WHERE table_schema = 'business' AND table_name = 'NumberOfColumns'; The output displays the number of columns.

How do I add a column to a table in MySQL?

Syntax. The syntax to add a column in a table in MySQL (using the ALTER TABLE statement) is: ALTER TABLE table_name ADD new_column_name column_definition [ FIRST | AFTER column_name ];


1 Answers

You can do this

INSERT INTO `message` VALUES (NULL, '7');

This will match the number of columns and ignore the null insert into the auto increment id and insert the auto increment value;

like image 149
yaswanth Avatar answered Oct 06 '22 01:10

yaswanth