SQL column count does not match value count error

You must specify the column names when the number of values is not equal to the number of columns:

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

Typically when you have an Auto Incrementing field you don't want to specify the value for that column. Which means you remove that value from the VALUES

However as Johan points out, whenever the number of columns in the table doesn't match the number of columns you must specify the column list on the target table.

Its good practice to do anyway in case the number of columns or column order changes

INSERT INTO 
message
(p_id)
Values ('7')

You need to specify the columns you are inserting into. If you do not the Database assumes the values you are providing are values for each column and in the exact order of the columns according to the schema. Try the statement below.

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

In addition it is just good practice to always specify the columns in an insert statement. It helps for readability.

Tags:

Mysql

Sql