Tôi có bảng này:MySQL: # 1005 - Không thể tạo bảng (errno: 150) Khi tôi cố gắng tạo ra hơn 1 FK
CREATE TABLE IF NOT EXISTS `produtos` (
`id` int(11) NOT NULL auto_increment,
`idcatprodutos` int(11) NOT NULL,
`idcategoria` int(11) NOT NULL,
`idmarca` int(11) NOT NULL,
`nome` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
KEY `FK_produtos_2` (`idcatprodutos`),
KEY `FK_produtos_3` (`idmarca`),
KEY `FK_produtos_4` (`idcategoria`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC AUTO_INCREMENT=39 ;
và bảng này:
CREATE TABLE IF NOT EXISTS `sugestoes` (
`id` int(11) NOT NULL auto_increment,
`idproduto` int(11) NOT NULL,
`idsugestao1` int(11) NOT NULL,
`idsugestao2` int(11) NOT NULL,
`idsugestao3` int(11) NOT NULL,
`idsugestao4` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `FK_sugestoes_prod` (`idproduto`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=FIXED AUTO_INCREMENT=9 ;
Tôi đã tạo ra một fk sugestoes.idproduto -> produtos.id
làm việc, nhưng tôi muốn mỗi lĩnh vực khác cũng tham khảo các produtos.id
thông qua FK mới. Chạy lệnh dưới đây mà trở lại MySQL Lỗi: # 1005 - Không thể tạo bảng (errno: 150):
ALTER TABLE `infantile`.`sugestoes` ADD CONSTRAINT `FK_sugestoes_2` FOREIGN KEY `FK_sugestoes_2` (`idsugestao1`)
REFERENCES `produtos` (`id`)
ON DELETE SET NULL
ON UPDATE CASCADE
, ROW_FORMAT = FIXED;
Có ai có bất kỳ ý tưởng gì đang xảy ra?
Tại sao bạn thêm ', ROW_FORMAT = FIXED' vào trong' ALTER TABLE'? –