I have this table:
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 ;
and this table:
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 ;
I already created fk sugestoes.idproduto -> produtos.id , but I want each of the other fields to also produtos.id to the new FK. Run the following command that returns a MySQL error: # 1005 - Unable to create table (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;
Does anyone know what is going on?
user1068478
source share