Reputation: 31
I am trying to create a foreign key, but I am getting this error. I don't understand why. The query is:
click here to see the screenshot of the query
Upvotes: 0
Views: 5367
Reputation: 1948
It is because you have given a wrong reference. You need to reference the primary key of another table, not just the table. See this example-
CREATE TABLE parent (id INT NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE child (
id INT,
parent_id INT,
PRIMARY KEY (`id`),
FOREIGN KEY (parent_id) REFERENCES parent(id)
ON DELETE CASCADE
);
Upvotes: 4