mysql 为什么创建不了 s_c表 出现[Err] 1005 - Can't create table 'xx' (errno: 150)
createdatabaseifnotexists`gongjiao`;USE`gongjiao`;/*Tablestructurefortable`car`*/DROP...
create database if not exists `gongjiao`;
USE `gongjiao`;
/*Table structure for table `car` */
DROP TABLE IF EXISTS `car`;
CREATE TABLE `car` (
`cid` varchar(255) NOT NULL,
`cintr` varchar(255) DEFAULT NULL,
`endt` varchar(255) DEFAULT NULL,
`money` int(11) DEFAULT NULL,
`start` varchar(255) DEFAULT NULL,
PRIMARY KEY (`cid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*Data for the table `car` */
insert into `car` values
('116','116?????','19:30',1,'5:30'),
('119','119??','22:00',1,'5:00');
/*Table structure for table `s_c` */
DROP TABLE IF EXISTS `s_c`;
CREATE TABLE `s_c` (
`cid` varchar(255) NOT NULL,
`sid` varchar(255) NOT NULL,
PRIMARY KEY (`cid`,`sid`),
KEY `FK1BB97A20E41A` (`sid`),
KEY `FK1BB977C33D008` (`cid`),
CONSTRAINT `FK1BB977C33D008` FOREIGN KEY (`cid`) REFERENCES `car` (`cid`),
CONSTRAINT `FK1BB97A20E41A` FOREIGN KEY (`sid`) REFERENCES `stop` (`sid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*Data for the table `s_c` */
insert into `s_c` values
('116','??'),
('119','??'),
('116','???'),
('119','???'),
('119','???'); 展开
USE `gongjiao`;
/*Table structure for table `car` */
DROP TABLE IF EXISTS `car`;
CREATE TABLE `car` (
`cid` varchar(255) NOT NULL,
`cintr` varchar(255) DEFAULT NULL,
`endt` varchar(255) DEFAULT NULL,
`money` int(11) DEFAULT NULL,
`start` varchar(255) DEFAULT NULL,
PRIMARY KEY (`cid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*Data for the table `car` */
insert into `car` values
('116','116?????','19:30',1,'5:30'),
('119','119??','22:00',1,'5:00');
/*Table structure for table `s_c` */
DROP TABLE IF EXISTS `s_c`;
CREATE TABLE `s_c` (
`cid` varchar(255) NOT NULL,
`sid` varchar(255) NOT NULL,
PRIMARY KEY (`cid`,`sid`),
KEY `FK1BB97A20E41A` (`sid`),
KEY `FK1BB977C33D008` (`cid`),
CONSTRAINT `FK1BB977C33D008` FOREIGN KEY (`cid`) REFERENCES `car` (`cid`),
CONSTRAINT `FK1BB97A20E41A` FOREIGN KEY (`sid`) REFERENCES `stop` (`sid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*Data for the table `s_c` */
insert into `s_c` values
('116','??'),
('119','??'),
('116','???'),
('119','???'),
('119','???'); 展开
2个回答
展开全部
1.找不到主表中 引用的列
2.主键和外键的字符编码不一致
3.外键字段与要做外键校验的字段类型不匹配
4.MySQL支持外键约束,并提供与其它DB相同的功能,但表类型必须为 InnoDB,非InnoDB 存储引擎会导致报错。
5.建外键的表的那个列没有index
2.主键和外键的字符编码不一致
3.外键字段与要做外键校验的字段类型不匹配
4.MySQL支持外键约束,并提供与其它DB相同的功能,但表类型必须为 InnoDB,非InnoDB 存储引擎会导致报错。
5.建外键的表的那个列没有index
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |