mysql - SQL - many to many table wont work -
#1005 - can't create table 'ass1 lol.management' (errno: 150) (details...)
i'm having above error returned when try create many many table
trying create many many table between employees , supervisors, not error returned when make supervisor , employee tables. when go create management table above error.
these create table statements
employee table
create table if not exists employee ( emp_id int(4) not null, yr_ser int(4), status varchar(30), emp_name varchar(30), emp_gen varchar(1), primary key (emp_id) );
supervisor table
create table if not exists supervisor ( sup_id int(4) not null, sup_name varchar(30) not null, gen int(4), dep_id int(4), primary key (sup_id), index (dep_id), foreign key (dep_id) references department(dep_id) on update cascade on delete restrict );
but when go create table error
management table
create table if not exists management ( emp_id int(4) not null, sup_id int(4) not null, primary key (emp_id, sup_id), index (emp_id), index (sup_id), foreign key (emp_id) references employee(emp_id) on update cascade on delete restrict, foreign key (sup_id) references supervisor(act_id) on update cascade on delete restrict );
help appreciated, thank you.
your may-to-many table references field act_id
in supervisor
table, no such field defined. should sup_id
instead:
create table if not exists management ( emp_id int(4) not null, sup_id int(4) not null, primary key (emp_id, sup_id), index (emp_id), index (sup_id), foreign key (emp_id) references employee(emp_id) on update cascade on delete restrict, foreign key (sup_id) references supervisor(sup_id) -- here on update cascade on delete restrict );
Comments
Post a Comment