最近在用数据库时,添加外键总是报错Can't create table (errno: 150)。两张建表命令分别是:
CREATE TABLE `resource_1` (
`id` int(20) unsigned NOT NULL auto_increment,
`provider` varchar(20) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=InnoDB
和
CREATE TABLE `resource_2` (
`id` int(20) unsigned NOT NULL ,
`title` varchar(128) NOT NULL default '',
FOREIGN KEY (`id`) REFERENCES `resource` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) TYPE=InnoDB
从网上查了下解决方法,主要是三种:
1.表类型需是InnoDB,其他类型不支持FOREIGN KEY ,这里我已经设置成InnoDB了;