ERROR MESSAGE: #1215 - Cannot add foreign key constraint
hello i can't create table foreign key... how to do this... i have two table..
the first table got two primary key then the 2nd table is 1 primary key...
the first table is
courseid varchar(5)
and courseyear int
and the second is subj_id varchar(5)
create table studentload(
student_id varchar(11) not null,
courseid varchar(5) not null,
courseyear int not null,
subj_id varchar(5) not null,
foreign key (courseid,courseyear) references course(courseid,courseyear),
foreign key (subj_id) references subject(subj_id)
)
EDIT
this is all table that I inserted already
CREATE TABLE IF NOT EXISTS `course` (
`courseid` varchar(5) NOT NULL,
`courseyear` int(11) NOT NULL,
`coursedesc` varchar(50),
`subj_id` varchar(5) NOT NULL,
PRIMARY KEY (`courseid`,`courseyear`)
)
CREATE TABLE IF NOT EXISTS `subject` (
`subj_id` varchar(5) NOT NULL,
`subj_name` varchar(50) NOT NULL,
`courseid` varchar(5),
`courseyear` int(11),
foreign key (`courseid`,`courseyear`) references `courseid` (`courseid`,`courseyear`)
)