create table Artist
(
id INT auto_increment primary key,
name char(20),
birthday date,
sex char(2),
imdbnumber char(9),
introduction varchar(100)
);
create table Movie
(
id INT auto_increment primary key,
name char(20),
releasedate date,
duration int,
language char(8),
introduction varchar(100)
);
create table Participation
(
id INT auto_increment primary key,
artistid int,
movieid int,
rolename char(20),
foreign key(artistid) references Arist(id),
foreign key(movieid) references Movie(id) 
);
它一直报错code error 1215,这是为什么

解决方案 »

  1.   

    foreign key(artistid) references Arist(id),  这句里面的表名写错了,太粗心啦,这20分应该归我了,这百分百是唯一答案;把 Arist 改成 Artist;
      

  2.   

    错误码1215的含义是:
    MySQL error code 1215 (ER_CANNOT_ADD_FOREIGN): Cannot add foreign key constraint
    楼上正解,就是因为表名写错导致外键约束建立失败。mysql安装后会附带一个命令行工具perror,可以用来查询各种错误码的具体含义。