mysql - #1005 - Can't create table 'xxx.item' (errno: 150) -
i creating database hotel , not able create "item"
table.
the error shown
#1005 - can't create table 'xxx.item' (errno: 150)
below sql queries:
create table menu ( menu_id int , menu_name varchar(100) , primary key (menu_id) ); create table categories ( categories_id int , category_name varchar(100) , primary key (categories_id) ); create table menu_category_item ( mci_id int , menu_id int , categories_id int , item_id int , item_type int , restaurant_id int , primary key (mci_id) , foreign key (menu_id) references menu(menu_id) , foreign key (categories_id) references categories(categories_id) , foreign key (restaurant_id) references restaurants(restaurant_id) ); create table item ( item_id int , item_name varchar(100) , item_price decimal , foreign key (item_id) references menu_category_item (item_id) );
please me out of this!!
i think problem in structure of database, should have item_id primary key in item table, let menu_category_item table reference that. like:
create table item ( item_id int , item_name varchar(100) , item_price decimal , primary key (item_id)); create table menu_category_item ( mci_id int , menu_id int , categories_id int , item_id int , item_type int , restaurant_id int , primary key (mci_id) , foreign key (menu_id) references menu(menu_id) , foreign key (categories_id) references categories(categories_id) , foreign key (restaurant_id) references restaurants(restaurant_id) , foreign key (item_id) references item(item_id) );
if i'm correct, item table contain items, need primary key there. , menu_item_category matching items menus, there add foreign key.
comment @adam below:
as rule: 1 - every table should have primary key , 2 - foreign keys should against primary key target table. there exceptions, rules starting places basic db design imo
Comments
Post a Comment