Recently I upgraded My Magento 2.2.6 to 2.3, After upgrading I configured Multi Source Inventory, It is working as expected while creating new products (and products created after upgradation). But it is throwing error while updating old products (which were created before upgrading to 2.3).
Below error is thrown by system while saving old products-
The stock item was unable to be saved. Please try again.
In exception.log
there is below log for the error-
main.CRITICAL: The stock item was unable to be saved. Please try
again. {"exception":"[object]
(Magento\Framework\Exception\CouldNotSaveException(code: 0): The
stock item was unable to be saved. Please try again. at
/magento_root/vendor/magento/module-catalog-inventory/Model/Stock/StockItemRepository.php:187,
Magento\\Framework\\Exception\\CouldNotSaveException(code: 0):
Could
not save Source Item at
/magento_root/vendor/magento/module-inventory/Model/SourceItem/Command/Handler/SourceItemsSaveHandler.php:78
,
Zend_Db_Statement_Exception(code: 23000): SQLSTATE[23000]: Integrity
constraint violation: 1452 Cannot add or update a child row: a foreign
key constraint fails (magento_db
.inventory_source_item
, CONSTRAINT
INVENTORY_SOURCE_ITEM_SOURCE_CODE_INVENTORY_SOURCE_SOURCE_CODE
FOREIGN KEY (source_code
) REFERENCESinventory_source
(source_code
) ON DEL), query was: INSERT INTO inventory_source_item
(source_code
,sku
,quantity
,status
) VALUES (?, ?, ?, ?) ON
DUPLICATE KEY UPDATEquantity
= VALUES(quantity
),status
=
VALUES(status
) at
/magento_root/vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:235,
PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint
violation: 1452 Cannot add or update a child row: a foreign key
constraint fails (magento_root
.inventory_source_item
, CONSTRAINT
INVENTORY_SOURCE_ITEM_SOURCE_CODE_INVENTORY_SOURCE_SOURCE_CODE
FOREIGN KEY (source_code
) REFERENCESinventory_source
(source_code
) ON DEL) at
/magento_root/vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:228)"}
[]
Does anyone have idea about this issue?
Best Answer
Simple solution if you are not planning to use MSI you can simply disable all modules related to it by using below
As you are reading this you probably planning to use MSI so here's how you can solve it :),
In MSI
inventory_source_item
table is responsible for inventory management. Make sure that products whic you migrated to 2.3.x are exists in table.If not then try to add those manually for a particular SKU like,
Enter in
inventory_source_item
with your desired qty and with source code.See below screenshot.
Here I've no qty so data is like 0.0000 you can add your desired qty.
Note : if you've multiple source then add new entry to that table with different source.
Hope it will solve your problem.