0
I have an employee chart and address. The address is receiving a foreign key from the employee, however, is giving the following error when I will insert:
Exception 'Pdoexception' with message 'SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot add or update a Child Row: a Foreign key Cont straint fails
How do I fix it?
$consulta = "INSERT INTO ENDERECO (FUNCIONARIO_FUN_CODIGO)
VALUES(:codigoFuncionario)";
try{
$resultado=$db_con->prepare($consulta);
//$resultado->BindParam(':cep',$cep,PDO::PARAM_STR);
$resultado->BindParam(':codigoFuncionario',$codigoFuncionario,PDO::PARAM_STR);
$resultado->execute();
Only with the error message becomes difficult to help, post your codes
– MarceloBoni
That one
FUNCIONARIO_FUN_CODIGO
as I understand it makes reference to another table, correct? Check if what you are entering in this value exists in this other table to which reference.– MarceloBoni
Yes, I checked and there is
– Rodrigo Caio
Where is this $code variable coming from Feature? ?
– Rodrigo Teixeira Andreotti
Another detail, what @Marceloboni commented is very correct, the error says that the information being inserted in the address table does not exist in the other table, check these items.
– Rodrigo Teixeira Andreotti
Checks if you have not set FUNCIONARIO_FUN_CODIGO to auto-increment
– Sveen