We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails

i can insert data from mysql, but i try to insert from phalcon and the SQLSTATE[23000] shows up

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (laboratoriocygnus.datospersonales, CONSTRAINT fk_datosPersonales_usuario1 FOREIGN KEY (usuario) REFERENCES usuario (id) ON DELETE NO ACTION ON UPDATE NO ACTION)



1.4k
Accepted
answer

it's sql error. you try add or update row where foreign key is empty or not exist in dependent table.



4.7k
edited Feb '19

it's working now, i use phalcon model table --force, maybe i change something in the model and that generated the problem