I\'m getting this error: ERROR 1005 (HY000): Can\'t create table (errno: 150);
I know it has something to do with the foreign keys but I have checked to see if they
You have FK definitions that will try to set a null value on non null columns. Therefore that FK declaration is impossible.
CREATE TABLE IF NOT EXISTS registration (
branchNo VARCHAR (15) NOT NULL,
memberNo VARCHAR (15) **NOT NULL**,
StaffNo VARCHAR (15) **NOT NULL**,
dateJoined date NOT NULL,
PRIMARY KEY (branchNo, memberNo),
FOREIGN KEY (memberNo) REFERENCES member (memberNo) ON DELETE **SET NULL** ON UPDATE
CASCADE,
FOREIGN KEY (StaffNo) REFERENCES staff (StaffNo) ON DELETE **SET NULL** ON UPDATE
CASCADE
) ENGINE=InnoDB;
you can either set "on DELETE CASCADE" or allow those fields to be null.
You might have the same error on other tables. I just stopped at the first error I found :)
Solved:
Check to make sure Primary_Key and Foreign_Key are exact match with data types.
If one is signed another one unsigned, it will be failed.
Good practice is to make sure both are unsigned INT.