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
.
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.
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.
mysql> SELECT COUNT(*) AS NUMBEROFCOLUMNS FROM INFORMATION_SCHEMA. COLUMNS -> WHERE table_schema = 'business' AND table_name = 'NumberOfColumns'; The output displays the number of columns.
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 ];
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With