hi ppl,

i am having issue updating the table with details from edited form, and it turns out to be foreign key constraint issue.

the error i am getting is,
================================
Cannot add or update a child row: a foreign key constraint fails (`****`.`purchase_order_detail`, CONSTRAINT `purchase_order_detail_component_item_id_component_item_id` FOREIGN KEY (`component_item_id`) REFERENCES `component_item` (`id`))
=================================
table:purchase_order_detail
foreign key: component_item_id
this is the key which links the table purchase_order_detail and component_item

in one of the threads i came across similar issue, where a member said, "While specifying the foreign key constraint you have specified "ON UPDATE NO ACTION" while this seems to mean that no action would be taken on update, it specifically means that you will not be allowed to update too, either remove the clause or if it is binding for you to have it, modify it suitably."

can anyone pls help me with this issue?? is it possible to modify so that "rows are updated on update", if so how do i do it...
pls help me this or post links to any tutorial where i can learn to do this..

thanks..

Recommended Answers

All 4 Replies

frens, more details on this issue, i checked in the "relation view" in phpmyadmin n this field component_item_id is not set on "ON UPDATE NO ACTION". i am using symfony framework, could this issue have raised because of symfony??

any suggestion in this direction most appreciated.

thanks a lott..

My initial guess after reading this, is that you are either not supplying a value for `component_item_id` (which can not be null) OR you are supplying a value which does not exist in your component_item table.

Can you post both the structure of your two tables, and also the query you are using.

hi, it turns out that, i am trying to update the foreign key component_item_id. is it not possible to update foreign key??
i am new to db, could you pls explain what happens if i set this foreign key as ON UPDATE CASCADE.

Seeing the table structures would make this much easier to answer correctly.

Generally:
If you are updating purchase_order_detail.`component_item_id` then you need to update it to a value that already exists in the component_item table.

If you are updating component_item.`id` then having the FK constraint on purchase_order_detail.`component_item_id` set to ON UPDATE CASCADE would update the key in any table it was referenced.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.