I am trying to add foreign key constraints to two existing tables. I have gone through MySQL documentations and some other posts about this issue on Stack Overflow however error code 1215 comes up.
Can someone help me identify my issue/error.
Here are my two existing tables:
---Books
CREATE TABLE Books(
ISBN VARCHAR (13) NOT NULL,
title VARCHAR(60) NOT NULL,
pubDate DATE NOT NULL,
PubID INT NOT NULL,
cost DECIMAL (5,2) NOT NULL,
retail DECIMAL (5,2) NOT NULL,
discount DECIMAL (5,2) NOT NULL,
category ENUM('Fitness', 'Children', 'Computer', 'Cooking', 'Business', 'Literature') NOT NULL,
PRIMARY KEY(ISBN)
---Publishers
CREATE TABLE Publishers(
pubID INT NOT NULL,
name VARCHAR(60) NOT NULL,
contact VARCHAR(20),
phone VARCHAR(20)
);
Here is my Alter Statement
ALTER TABLE Books
ADD CONSTRAINT FK_pubID
FOREIGN KEY (pubID) REFERENCES Publishers(pubID);
I am aware that PubID has a capital P in the Books table and a lower pubID in the Publishers table, however I am still unsure.