-2
I have a table that I need to change to have a foreign key
ALTER TABLE bancocliente.product ADD CONSTRAINT fk_fabPro FOREIGN KEY (cod_fab) REFERENCES bancocliente.fabrica (code);
I get the error message:
Erro SQL (1452): Cannot add or update a child row: a foreign key constraint fails (`bancocliente`.`#sql-2eb8_2`, CONSTRAINT `fk_fabPro` FOREIGN KEY (`cod_fab`) REFERENCES `fabrica` (`code`))
Code of table creation:
CREATE TABLE `produto` (
`code` INT(11) NOT NULL AUTO_INCREMENT,
`cod_fab` INT(11) NOT NULL DEFAULT '0',
`nome` VARCHAR(50) NOT NULL,
`preco` FLOAT NOT NULL,
PRIMARY KEY (`code`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
AUTO_INCREMENT=1
;
and table manufactures
CREATE TABLE `fabrica` (
`code` INT(11) NOT NULL AUTO_INCREMENT,
`nome` VARCHAR(50) NOT NULL,
PRIMARY KEY (`code`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
AUTO_INCREMENT=6
;
Please avoid long discussions in the comments; your talk was moved to the chat
– Maniero