Why can't I add the foreign key group in note
?
I get Error Code: 1215. Cannot add foreign key constraint
.
create table student(
id_student int auto_increment not null,
prenume varchar(255) not null,
nume varchar(255) not null,
constraint id_student_pk_STUDENT primary key(id_student));
create table materie(
id_materie int auto_increment not null,
nume_materie varchar(255) not null,
constraint id_materie_pk_MATERIE primary key(id_materie));
create table inscris(
id_student int not null,
id_materie int not null,
constraint id_student_fk_INSCRIS foreign key(id_student) references student(id_student),
constraint id_materie_fk_INSCRIS foreign key(id_materie) references materie(id_materie));
create table note(
id_student int not null,
id_materie int not null,
nota int,
constraint fk_id_student_materie_NOTE foreign key(id_student, id_materie) references inscris(id_student, id_materie));
This is what show engine innodb status
says:
LATEST FOREIGN KEY ERROR\n------------------------\n2017-05-18 19:44:21 0x700007362000 Error in foreign key constraint of table catalog/note:\n foreign key(id_student, id_materie) references inscris(id_student, id_materie)):\nCannot find an index in the referenced table where the\nreferenced columns appear as the first columns, or column types\nin the table and the referenced table do not match for constraint.\nNote that the internal storage type of ENUM and SET changed in\ntables created with >= InnoDB-4.1.12, and such columns in old tables\ncannot be referenced by such columns in new tables.\nPlease refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-foreign-key-constraints.html for correct foreign key definition.