I have a table with a auto incremented id. The id is also a foreign key in another table. When I try to add values to these tables I get an exception - Column count doesn't match value count at row 1
These are my tables:
CREATE TABLE Hotspot(
num int auto_increment not null,
id varchar(255),
x int,
y int,
width int,
height int,
UNIQUE(id),
PRIMARY KEY (num)
);
CREATE TABLE Hotspot_Label(
num int auto_increment not null,
question_id varchar(255),
hotspot_id varchar(255),
label_id varchar(255),
PRIMARY KEY (num),
FOREIGN KEY (hotspot_id)
REFERENCES Hotspot(id),
FOREIGN KEY (label_id)
REFERENCES Label(id),
FOREIGN KEY (question_id)
REFERENCES Question(id)
);
This is the stored procedure for one of the tables
PROCEDURE `insertHotspot`(IN recID varchar(255), x int, y int, width int, height int)
BEGIN
INSERT INTO Hotspot VALUES(recID, x, y, width, height);
END
I have read that you don't need to insert an auto increment value in the stored procedure so I can't see what's going wrong
INSERT INTO Hotspot VALUES(num,recID, x, y, width, height);
It should be like above You left the column
Num
which is auto incremented although it doesn't need any value to be added the column count decreases if you miss it.