mysql - Error 1215: Why is it happening? -


i confused why error 1215: cannot add foreign key constraint occurring in code. have ideas?

the first 4 tables create fine, error thrown when try create stars table. not sure what's going wrong, keys being referenced primary keys , must unique , non-null. plus, keys exist previous tables have been created first. might stupid mistake made, better have fresh eyes @ it, right?

this database simplistic because i'm doing school assignment.

create table movieexec ( execname varchar(40), certnum numeric(30, 0), address varchar(50), networth real, primary key(execname), unique key(certnum) );  create table stud ( studname varchar(30), address varchar(50), prescnum numeric(30, 0), primary key(studname), foreign key (prescnum) references movieexec(certnum) );  create table moviestar( starname varchar(30), address varchar(50), gender varchar(1),  birthdate date, primary key(starname) );  create table movies ( movietitle varchar(30), movieyear numeric(4,0),  length numeric(3,0), genre varchar(30), studioname varchar(30), producercnum numeric(30, 0), primary key (movietitle, movieyear), foreign key (producercnum) references movieexec(certnum), foreign key (studioname) references stud(studname) );  create table stars ( movietitle varchar(30),  movieyear numeric(4,0), starname varchar(30), primary key (movietitle, movieyear, starname), foreign key (movietitle) references movies(movietitle), foreign key (movieyear) references movies(movieyear), foreign key (starname) references moviestar(starname) ); 

it should composite foreign key title , year:

foreign key (movietitle, movieyear) references movies(movietitle, movieyear), foreign key (starname) references moviestar(starname) 

it should composite because that's exact pk of movies table , that's unique combination there available.

then @cbroe mentioned in answer idea index stars.starname column.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -