Kawazoe Kazuke
Kawazoe Kazuke

Reputation: 175

Database Error Occured CodeIgniter 3.0

Below error message show up on data entry.

Error Number: 1452

Cannot add or update a child row: a foreign key constraint fails (`mail_sys_db`.`user_plan_original_item`, CONSTRAINT `user_plan_original_item_ibfk_1` FOREIGN KEY (`user_plan_detail_id`) REFERENCES `user_plan_detail` (`user_plan_detail_id`))

INSERT INTO user_plan_original_item (user_plan_original_item_id,user_plan_detail_id,original_item_id,item_value) VALUES ('1','121','1','a')

Upvotes: 0

Views: 78

Answers (1)

Mayank Pandeyz
Mayank Pandeyz

Reputation: 26258

The error do not have any relation with codeigniter, its a mysql error. Take a look at the following:

Foreign key relationships involve a parent table that holds the central data values, and a child table with identical values pointing back to its parent. The FOREIGN KEY clause is specified in the child table.

It will reject any INSERT or UPDATE operation that attempts to create a foreign key value in a child table if there is no a matching candidate key value in the parent table.

Means that, you are trying to add a row to your child table for which no matching row is present in parent table.

Upvotes: 2

Related Questions