Inserting rows in SQL, Keep getting error message #1136 - Column count doesn't match value count at row 1

StackOverflow https://stackoverflow.com/questions/21934516

  •  14-10-2022
  •  | 
  •  

Question

Hi am trying to add in rows to my table "members" however i keep getting an error message.

#1136 - Column count doesn't match value count at row 1

I have another table called "user" where I have the user_id as the primary key. In members table I have user_id as the foreign key.

Can anyone help me?

INSERT INTO members (user_id, membership_number, weight, height, progress, meal_plan, my_programme, trainer_id, bank, card_number, sort_code, valid, exp, security_number) VALUES ('2','0001','75kgs', '6ft', 'lost 5kgs', 'chicken and rice', '2', 'HSBC', '1234123412341234', '401725', '01-12', '01-16', '521');

Was it helpful?

Solution 2

You are inserting only 13 values..you are missing my_programme value..

#  field             value
--------------------------
 1 user_id           2
 2 membership_number 0001
 3 weight            75kgs
 4 height            6ft
 5 progress          lost 5kgs
 6 meal_plan         chicken and rice
 7 my_programme      ?????
 8 trainer_id        2
 9 bank              HSBC
10 card_number       1234123412341234
11 sort_code         401725
12 valid             01-12
13 exp               01-16
14 security_number   521

INSERT INTO members (user_id, membership_number, weight, height, progress, meal_plan,
my_programme, trainer_id, bank, card_number, sort_code, VALID, exp, security_number)
VALUES ('2',
        '0001',
        '75kgs',
        '6ft',
        'lost 5kgs',
        'chicken and rice',
        'some value', <------------- Value for my_programme 
        '2',
        'HSBC',
        '1234123412341234',
        '401725',
        '01-12',
        '01-16',
        '521');

OTHER TIPS

That's because you are trying to insert 13 values into a 14 column set.

#  field             value
--------------------------
 1 user_id           2
 2 membership_number 0001
 3 weight            75kgs
 4 height            6ft
 5 progress          lost 5kgs
 6 meal_plan         chicken and rice
 7 my_programme      ???
 8 trainer_id        2
 9 bank              HSBC
10 card_number       1234123412341234
11 sort_code         401725
12 valid             01-12
13 exp               01-16
14 security_number   521

Nagaraj S is right. you omitted "my_programme"

The error message says it all.

You've listed fourteen columns to add data to, but only gave thirteen values to insert into the table.

The fact that user_id is a foreign key is irrelevant; the insert statement does not reference the user table.

The number of values in the list after VALUES is not the same as the number of fields in the query. You have 14 columns in the INSERT, but only supplying 13 VALUES

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top