I am currently working through my MySQL task and have come across a small hiccup whilst using foreign keys. The problem is as follows:
CREATE TABLE IF NOT EXISTS entries(
student_id INT(10) UNSIGNED NOT NULL,
subject_name INT(10) UNSIGNED NOT NULL,
exam_date VARCHAR(20) NOT NULL,
PRIMARY KEY (exam_date),
FOREIGN KEY (student_id) REFERENCES student (student_id),
FOREIGN KEY (subject_name) REFERENCES subject (subject_name));
After i enter this code Error 1215 pops up saying that i cannot add foreign key constraints. The error is shown below:
ERROR 1215 (HY000): Cannot add foreign key constraint
The table i am trying to link the foreign key is this:
CREATE TABLE IF NOT EXISTS subjects(
student_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
subject_name VARCHAR(20) NOT NULL,
level_of_entry VARCHAR(20),
exam_board VARCHAR(40) NOT NULL,
PRIMARY KEY(student_id));
I have no issues with this table and simply wonder how i could solve my dilemma?