Unable to add record due to database constraints

I am currently working on an application but ran into the error below. I am trying to delete all related data when I delete a main record.

Full error:




CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`engleepl`.`qualifications`, CONSTRAINT `Delete Qualification` FOREIGN KEY (`id`) REFERENCES `users` (`id`) ON DELETE CASCADE). The SQL statement executed was: INSERT INTO `qualifications` (`user_id`, `graduation_date`, `qualification`, `institution`, `updated_on`) VALUES (:yp0, :yp1, :yp2, :yp3, :yp4)



Currently, I have a "Users table" that have the following related table:

  • Biodata

  • Qualifications

I have configured relations in "Users" model as follow:




    public function relations()

{

    $relations = Yii::app()->getModule('user')->relations;

    if (!isset($relations['profile']))

        $relations['profile'] = array(self::HAS_ONE, 'Profile', 'user_id');

        $relations['biodata'] = array(self::HAS_ONE, 'Biodata', 'user_id');

        $relations['qualifications'] = array(self::HAS_ONE, 'Qualifications', 'user_id');

    return $relations;

}



In phpmyadmin, I have set the same configuration for both "Biodata" and "Qualifications" as such:

Internal relations:

  • id from "Users" is Foreign Key to user_id in "Biodata" and "Qualifications"

  • Action constraint properties: I have added "Cascade on delete"

I may have missed certain steps or overlooked certain codes. How would I go about overcoming this issue?

Any suggestions? Thank you.