SQL error: 1452: cannot add or update child row: foreign key constraint is not fulfilled

I have two tables in my database:

  • order;
  • course.

orderhas a column courseidthat refers to a idtable column course. Whenever I tried to do saveAll()in CakePHP, the above error will be displayed SQLand the data will not be saved.

+3
source share
2 answers

What this sounds like is that between your tables you have a foreign key constraint in the database. This means that in the course_id column you cannot insert values ​​other than identifiers from an external table.

The above error means that when sending your data, the foreign field is empty or absent.

: 1. , NULL. , , NULL, 2. , : $this- > data ['Order'] ['course_id'], , . 1.

+16

- , . ORM , , , , . :

-

    $user = ORM::factory('user');
    $user->username = 'SomeoneSpecial";

    if ($user->add(ORM::factory('role', 'login') && $user->save() ) {
        // continue on with code
    }

, , , , , .

0

All Articles