关于ERROR 1005 (HY000): Can't create table 'o2o.tb_product' (errno: 121)
来源:2-4 实体类设计与表创建C
qq_慕仔309552
2019-11-08
create table tb_product( product_id int(100) NOT NULL AUTO_INCREMENT, product_name varchar(100) NOT NULL, product_desc varchar(2000) DEFAULT NULL, img_addr varchar(2000) DEFAULT ‘’, normal_price varchar(100) DEFAULT NULL, promotion_price varchar(100) DEFAULT NULL, priority int(2) NOT NULL DEFAULT ‘0’, create_time datetime DEFAULT NULL, last_edit_time datetime DEFAULT NULL, enable_status int(2) NOT NULL DEFAULT ‘0’, product_category_id int(11) DEFAULT NULL, shop_id int(20) NOT NULL DEFAULT ‘0’, PRIMARY KEY(product_id), CONSTRAINT fk_product_procate FOREIGN KEY(product_category_id) REFERENCES tb_product_category(product_category_id), CONSTRAINT fk_product_shop FOREIGN KEY (shops_id) REFERENCES tb_shop (shop_id) )ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=UTF8;这段sql出现了121错误,查询了是说外键重名了,但是我前面的命名都是跟老师的一样,是不是有个索引关节出问题了,请问怎么解决,换个外键名字说外键名不存在
1回答
-
同学好,同学可以执行这个
DROP TABLE IF EXISTS `tb_product`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `tb_product` ( `product_id` int(100) NOT NULL AUTO_INCREMENT, `product_name` varchar(100) NOT NULL, `product_desc` varchar(2000) DEFAULT NULL, `img_addr` varchar(2000) DEFAULT '', `normal_price` varchar(100) DEFAULT NULL, `promotion_price` varchar(100) DEFAULT NULL, `priority` int(2) NOT NULL DEFAULT '0', `create_time` datetime DEFAULT NULL, `last_edit_time` datetime DEFAULT NULL, `enable_status` int(2) NOT NULL DEFAULT '0', `product_category_id` int(11) DEFAULT NULL, `shop_id` int(20) NOT NULL DEFAULT '0', PRIMARY KEY (`product_id`), KEY `fk_product_procate_1` (`product_category_id`), KEY `fk_product_shop_1` (`shop_id`), CONSTRAINT `fk_product_procate_1` FOREIGN KEY (`product_category_id`) REFERENCES `tb_product_category` (`product_category_id`), CONSTRAINT `fk_product_shop_1` FOREIGN KEY (`shop_id`) REFERENCES `tb_shop` (`shop_id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
试试,然后如果不行,得确保tb_product_category以及tb_shop 这两张表已经先于tb_product创建
122019-11-09
相似问题
回答 2