mysql - ERROR 1005 (HY000): Can't create table 'Item_Copy' (errno: 150) unable to create table Item_Copy -
i cannot create table item_copy
create table library ( library_id int primary key, library_address varchar(40), library_phone bigint ); create table branch ( library_id int, branch_number int, branch_name varchar(40), branch_address varchar(40), branch_phone bigint, branch_hours varchar(40), primary key (library_id,branch_number), foreign key (library_id) references library(library_id) ); create table item_copy ( item_id int primary key, copy_number int, copy_condition varchar(40), copy_date_acquired date, copy_cost int, library_id int, branch_number int, foreign key (library_id) references branch(library_id), foreign key (branch_number) references branch(branch_number), foreign key (item_id) references item(item_id) );
just scientific guess (will drop if it's wrong) (is based on assumption item_id definitions match):
you wanted compound foreign key, not 2 separated fks:
foreign key (library_id, branch_number) references branch(library_id, branch_number)
Comments
Post a Comment