CREATE TABLE `hr_famousperson` (
`PERSONID` int(10) NOT NULL AUTO_INCREMENT,
`NAME` varchar(50) NOT NULL,
`photo` varchar(500) DEFAULT NULL,
`COMPANY` varchar(50) DEFAULT NULL,
`STYLEID` int(10) unsigned DEFAULT NULL,
`REMARK` varchar(500) DEFAULT NULL,
`CONTENTURL` varchar(200) DEFAULT NULL,
`PUBLISHDATE` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`VIEWTIMES` int(10) NOT NULL DEFAULT '0',
`PHOTONAME` varchar(50) DEFAULT NULL COMMENT '相片文件名',
PRIMARY KEY (`PERSONID`),
KEY `FK_hr_famousperson_styleid` (`STYLEID`) USING BTREE,
CONSTRAINT `FK_hr_famousperson_styleid` FOREIGN KEY (`STYLEID`) REFERENCES `hr_personstyle` (`STYLEID`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8
执行这条创建表的语句的时候,出现如下错误。
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
CONSTRAINT `FK_hr_famousperson_styleid` FOREIGN KEY (`STYLEID`) R' at line 13
Query OK, 0 rows affected (0.00 sec)
ERROR 1146 (42S02): Table 'cmcchr.hr_famousperson' doesn't exist
ERROR 1146 (42S02): Table 'cmcchr.hr_famousperson' doesn't exist
ERROR 1146 (42S02): Table 'cmcchr.hr_famousperson' doesn't exist
ERROR 1146 (42S02): Table 'cmcchr.hr_famousperson' doesn't exist
Query OK, 0 rows affected (0.00 sec)
1,MySQL支持外键约束,并提供与其它DB相同的功能,但表类型必须为 InnoDB
2,建外键的表的那个列要加上index
以上两点都是满足了,但是还是提示错误,
解决办法如下:
SET FOREIGN_KEY_CHECKS = 0;
执行语句,
SET FOREIGN_KEY_CHECKS = 1;
OK,问题解决。。
阅读(1238) | 评论(0) | 转发(0) |