webERP Forum

Full Version: Database Error 1452: unable to insert a new work order
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I can't invoice for a particular product. I get an error, Cannot add or update a child row: a foreign key constraint fails

Database Error 1452 : Unable to insert a new work order for the sales order item
Cannot add or update a child row: a foreign key constraint fails (`DB`.`workorders`, CONSTRAINT `worksorders_ibfk_1` FOREIGN KEY (`loccode`) REFERENCES `locations` (`loccode`))

Database Rollback Due to Error Above : Rolling Back Transaction OK

/DeliveryDetails.php?identifier=1653646435
(05-27-2022, 09:56 PM)wissedenis22 Wrote: [ -> ]I can't invoice for a particular product. I get an error, Cannot add or update a child row: a foreign key constraint fails

Database Error 1452 : Unable to insert a new work order for the sales order item
Cannot add or update a child row: a foreign key constraint fails (`DB`.`workorders`, CONSTRAINT `worksorders_ibfk_1` FOREIGN KEY (`loccode`) REFERENCES `locations` (`loccode`))

Database Rollback Due to Error Above : Rolling Back Transaction OK

/DeliveryDetails.php?identifier=1653646435
can anyone help to make things clear. I see this
PHP Code:
($ErrMsg _('Unable to insert a new work order for the sales order item')) 
was included inĀ  DeliveryDetails.php

what does this mean, did I miss something in a primary table. Kindly help, any suggestion
I'll check this tomorrow to see what may be the situation, but does the item have a loccode?
Looking to the handling, is anything set for Default Factory Location at menu Setup => System Parameters?

The value to that setting is set to:
PHP Code:
$_SESSION['DefaultFactoryLocation'
...which is used as the loccode reference for the workorder insert at line 504 in DeliveryDetails.php.
(05-31-2022, 01:33 AM)TurboPT Wrote: [ -> ]Looking to the handling, is anything set for Default Factory Location at menu Setup => System Parameters?

The value to that setting is set to:
PHP Code:
$_SESSION['DefaultFactoryLocation'
...which is used as the loccode reference for the workorder insert at line 504 in DeliveryDetails.php.
Yeah I can see there a default factory location set, so what do you advice
I found that message is actually at 2 places in the DeliveryDetails file, so line 504 may not be the only place that can be the trouble.

Do you mind adding a couple of echo's to check?
If you might not have any local file modifications, I can attach a file with debug added, if that might be more desirable.

Anyway, add this before the query at line 499:
PHP Code:
echo __FILE__':'__LINE__" => wo: $WONo, loccode: {$_SESSION['DefaultFactoryLocation']}, end."

Add this before the query at line 697:
PHP Code:
echo __FILE__':'__LINE__" => wo: $WONo, loccode: {$_SESSION['Items'.$identifier]->Location}, end."


Then save, reproduce the error, to see what output displays on the page.

Also, check the loccode at the table level to ensure that it does not possibly have any leading/trailing white space that could cause a mismatch.
Can use this query, but replace the zzz portion with the known loccode:
Code:
SELECT loccode, length(loccode) FROM locations WHERE loccode like '%zzz%';