SQLSTATE[23000]: Integrity Constraint Violation

Asked

Viewed 898 times

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

  • 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.

  • Yes, I checked and there is

  • Where is this $code variable coming from Feature? ?

  • 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.

  • Checks if you have not set FUNCIONARIO_FUN_CODIGO to auto-increment

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.