错误消息:#1215 - 无法添加外键约束
你好我不能创建表外键...怎么做...我有两个表..第一个表有两个主键然后第二个表是一个主键...第一个表是
courseid varchar(5)
andcourseyear int
和第二个是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)
)
编辑
这是我已经插入的所有表格
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`)
)