I have a table that works fine like this:
id_table -> PK
id_quadra, id_setor_FK -> UK
CREATE TABLE IF NOT EXISTS `sic`.`quadra` (
`table_id` INT NOT NULL AUTO_INCREMENT ,
`id_quadra` INT NOT NULL ,
`id_setor_FK` INT NOT NULL ,
PRIMARY KEY (`table_id`) ,
INDEX `id_quadra_setor_FK` (`id_setor_FK` ASC) ,
UNIQUE INDEX `id_quadra_UK` (`id_quadra` ASC, `id_setor_FK` ASC) ,
CONSTRAINT `id_quadra_setor_FK`
FOREIGN KEY (`id_setor_FK` )
REFERENCES `sic`.`setor` (`table_id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
But If I add another FK (id_bairro_FK) that has nothing to do with the code above, it gives me error 150.
CREATE TABLE IF NOT EXISTS `sic`.`quadra` (
`table_id` INT NOT NULL AUTO_INCREMENT ,
`id_quadra` INT NOT NULL ,
`id_setor_FK` INT NOT NULL ,
`id_bairro_FK` INT NULL ,
`mapa` BLOB NULL ,
PRIMARY KEY (`table_id`) ,
INDEX `id_quadra_bairro_FK` (`id_bairro_FK` ASC) ,
INDEX `id_quadra_setor_FK` (`id_setor_FK` ASC) ,
UNIQUE INDEX `id_quadra_UK` (`id_quadra` ASC, `id_setor_FK` ASC) ,
CONSTRAINT `id_quadra_bairro_FK`
FOREIGN KEY (`id_bairro_FK` )
REFERENCES `sic`.`bairro` (`id_bairro` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `id_quadra_setor_FK`
FOREIGN KEY (`id_setor_FK` )
REFERENCES `sic`.`setor` (`table_id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
What the hell maybe hapenning?