Errors Adding Foreign Keys (MySQL) (Error Code 1215) -
i trying add foreign key between 2 different sets of tables, first set customer , shopping_cart. tried looking @ other posts regarding error couldn't work after looking @ them.
create table `usale`.`customer` ( create table `usale`.`customer` ( `customer_id` smallint unsigned not null auto_increment, `first_name` varchar(45) not null, `last_name` varchar(45) not null, `email` varchar(50) null default null, `active` tinyint(1) not null default true, `create_date` datetime not null, `last_update` timestamp null default current_timestamp, `student_student_id` bigint not null, `student_school_id` bigint not null, `shopping_cart_cart_id` tinyint unsigned not null, primary key (`customer_id`, `student_student_id`, `student_school_id`)), index `fk_customer_student1_idx` (`student_student_id` asc,`student_school_id` asc), index `fk_customer_shopping_cart1_idx` (`shopping_cart_cart_id` asc), constraint `fk_customer_student1` foreign key (`student_student_id`) references `usale`.`student` (`student_id`) on delete no action on update no action, constraint `fk_customer_shopping_cart1` foreign key (`shopping_cart_cart_id`) references `usale`.`shopping_cart` (`cart_id`) on delete no action on update no action) engine = innodb default character set = utf8;`customer_id` smallint unsigned not null auto_increment, `first_name` varchar(45) not null, `last_name` varchar(45) not null, `email` varchar(50) null default null, `active` tinyint(1) not null default true, `create_date` datetime not null, `last_update` timestamp null default current_timestamp, `student_student_id` bigint not null, `student_school_id` bigint not null, `shopping_cart_cart_id` tinyint unsigned not null, primary key (`customer_id`, `student_student_id`, `student_school_id`)) create table if not exists `frankapp`.`shopping_cart` ( `cart_id` bigint unsigned not null auto_increment, `last_update` timestamp not null default current_timestamp, `cart_total` decimal(12,2) null, primary key (`cart_id`)) engine = innodb default character set = utf8; alter table customer add constraint `fk_customer_shopping_cart1` foreign key (`shopping_cart_cart_id`) references `usale`.`shopping_cart`(`cart_id`) on delete no action on update no action
i'm getting error: "error: cannot add foreign key constraint error code: 1215"
for second set of tables named shopping_cart , shopping_cart_item
create table if not exists `usale`.`shopping_cart_item` ( `shopping_cart_item_id` bigint not null, `shopping_cart_cart_id` tinyint unsigned not null, `inventory_item_inventory_item_id` bigint unsigned not null, `inventory_item_student_id` bigint not null, `inventory_item_inventory_type` varchar(45) not null, `inventory_item_student_student_id` bigint not null, `inventory_item_student_customer_id` bigint not null, `inventory_item_student_school_id` bigint not null, `inventory_item_edition_edition_id` bigint unsigned not null, `inventory_item_edition_author_id` bigint not null, primary key (`shopping_cart_item_id`, `shopping_cart_cart_id`, `inventory_item_inventory_item_id`, `inventory_item_student_id`, `inventory_item_inventory_type`, `inventory_item_student_student_id`, `inventory_item_student_customer_id`, `inventory_item_student_school_id`, `inventory_item_edition_edition_id`, `inventory_item_edition_author_id`), index `fk_shopping_cart_items_shopping_cart1_idx` (`shopping_cart_cart_id` asc), index `fk_shopping_cart_item_inventory_item1_idx` (`inventory_item_inventory_item_id` asc, `inventory_item_student_id` asc, `inventory_item_inventory_type` asc, `inventory_item_student_student_id` asc, `inventory_item_student_customer_id` asc, `inventory_item_student_school_id` asc, `inventory_item_edition_edition_id` asc, `inventory_item_edition_author_id` asc)) create table if not exists `frankapp`.`shopping_cart` ( `cart_id` bigint unsigned not null auto_increment, `last_update` timestamp not null default current_timestamp, `cart_total` decimal(12,2) null, primary key (`cart_id`)) engine = innodb default character set = utf8; alter table shopping_cart_item add constraint `fk_shopping_cart_items_shopping_cart1` foreign key (`shopping_cart_cart_id`) references `usale`.`shopping_cart`(`cart_id`) on delete no action on update no action
once again getting error 1215: "error: cannot add foreign key constraint error code: 1215"
Comments
Post a Comment