3
I’m having trouble creating a foreign key from these tables:
Code:
ALTER TABLE `tb_permissao_view` ADD CONSTRAINT
`fk_tb_permissao_view_tb_sistema_pagina`
FOREIGN KEY (`cd_pagina`)
REFERENCES `tb_sistema_pagina` (`cd_pagina`);
Error:
ALTER TABLE `tb_permissao_view` ADD CONSTRAINT
`fk_tb_permissao_view_tb_sistema_pagina` FOREIGN KEY (`cd_pagina`)
REFERENCES `tb_sistema_pagina` (`cd_pagina`)
Error Code: 1452. Cannot add or update a child row:
a foreign key constraint fails (`portal`.`#sql-4ee_f`, CONSTRAINT
`fk_tb_permissao_view_tb_sistema_pagina` FOREIGN KEY (`cd_pagina`) REFERENCES
`tb_sistema_pagina` (`cd_pagina`))
tb_permissao_view
has recorded data already or both are empty?– user28595
Yes, both tables have records.
– Vinicius Miranda
There are probably values in
tb_permissao_view
in the columncd_pagina
that do not exist incd_pagina
of the reference tabletb_sistema_pagina
. Check if there really are divergent values in these two columns.– user28595
Thank you very much brother!
– Vinicius Miranda