Kirsty Meredith
Kirsty Meredith

Reputation: 113

Error Code: 1136. Column count doesn't match value count at row 1

I'm trying to insert the following info on MYSQL but keep getting the above error? Even if I just try to insert one of the values it keeps erroring out.

CREATE TABLE depositor
    (depositor_name   char(30),
    depositor_number  varchar(20),
    PRIMARY KEY (depositor_number),
    FOREIGN KEY (depositor_name)  REFERENCES depositor(depositor_name));

INSERT INTO depositor VALUES("Johnson", "A-101");
INSERT INTO depositor VALUES("Smith",   "A-215");
INSERT INTO depositor VALUES("Hayes",   "A-102");
INSERT INTO depositor VALUES("Hayes",   "A-101");
INSERT INTO depositor VALUES("Turner",  "A-305");
INSERT INTO depositor VALUES("Johnson", "A-201");
INSERT INTO depositor VALUES("Jones",   "A-217");
INSERT INTO depositor VALUES("Lindsay", "A-222");
INSERT INTO depositor VALUES("Majeris", "A-333");
INSERT INTO depositor VALUES("Smith",   "A-444");

SELECT * FROM DEPOSITOR

Upvotes: 3

Views: 21019

Answers (3)

Ameer Tamboli
Ameer Tamboli

Reputation: 1298

Just in case it helps anybody.

I was getting this error while firing insert and updates on table X. There was nothing wrong with the insert and update queries. I found out that there was trigger inserting the row being updated/inserted to other table Y. It didn't have equal number of columns. So it was throwing this error. Once I changed the table structure of Y, the error was resolved.

Upvotes: 6

eggyal
eggyal

Reputation: 125835

The foreign key is referencing itself, which doesn't make any sense (actually I'm surprised that MySQL allowed you to create it: I get an error when I try; perhaps your CREATE TABLE command failed without you noticing and you are attempting to INSERT into some previous version of the table which does not have two columns?).

Remove the foreign key constraint (and DROP any existing table).

Upvotes: 0

Toto
Toto

Reputation: 91373

Replace double quotes by single quotes:

INSERT INTO depositor VALUES('Johnson', 'A-101');

Upvotes: 1

Related Questions