I have two tb_Equipe and tb_Monitor tables. The tb_Equipe has relationship 1 / N with tb_Monitor , generating a foreign key in tb_Monitor .
To insert 'm using the code below :
public function Cadastrar($Mnovo)
{
$data['CGU'] = $Mnovo->getCGU();
$data['Nome'] = $Mnovo->getNome();
$data['CPF'] = $Mnovo->getCPF();
$data['Endereco'] = $Mnovo->getEndereco();
$data['Bairro'] = $Mnovo->getBairro();
$data['Cep'] = $Mnovo->getCep();
$data['Cidade'] = $Mnovo->getCidade();
$data['UF'] = $Mnovo->getUF();
$data['Complemento'] = $Mnovo->getComplemento();
$data['Senha'] = $Mnovo->getSenha();
$data['Telefone'] = $Mnovo->getTelefone();
$this->db->trans_begin();
$this->db->insert('tb_Monitor', $data);
if ($this->db->trans_status()===false) {
$this->db->trans_rollback();
return false;
}else{
$this->db->trans_commit();
return true;
}
}
But I get the following error seguite , run the code:
Error Number: 1452
Cannot add or update a child row: a foreign key constraint fails (`gbd`.`tb_monitor`, CONSTRAINT `fk_tb_Monitor_tb_Equipe` FOREIGN KEY (`idEquipe`) REFERENCES `tb_equipe` (`idEquipe`) ON DELETE NO ACTION ON UPDATE NO ACTION)
INSERT INTO `tb_Monitor` (`CGU`, `Nome`, `CPF`, `Endereco`, `Bairro`, `Cep`, `Cidade`, `UF`, `Complemento`, `Senha`, `Telefone`) VALUES ('8929999', 'Daniel', '00955674590', 'Rua Oito, 168', 'Centro', '95560-000', 'Rio de Janeiro', RJ', 'Apto ', '1234567890', '(54)8890-9089')
How do I resolve this issue foreign key ? I thank the attention .