4

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) REFERENCES inventory_source (source_code) ON DEL), query was: INSERT INTO inventory_source_item (source_code, sku, quantity, status) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE quantity = 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) REFERENCES inventory_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?

  • please check your log files – Aasim Goriya Jan 21 at 5:01
  • did you checked after indexing ? – Aasim Goriya Jan 21 at 5:09
  • yes I have done that also run all necessary commands – Piyush Jan 21 at 5:10
  • Issue seems must be because of reindexing, please reset reindex and re-index again. – Aasim Goriya Jan 21 at 5:11
  • @AasimGoriya I tried reset and reindex again, still same result – Piyush Jan 21 at 5:18
1

I had the same issue and after running the following commands works well:

rm -rf generated/*
php bin/magento indexer:reset
php bin/magento indexer:reindex
php bin/magento cache:clean
  • 1
    I had tried this commands but nothing worked – Piyush Feb 26 at 18:42
  • You should setup the inventory source for the product. See: Stores/Inventory/Source and Catalog/Inventory/Products/Sources – István Döbrentei Feb 26 at 19:22
  • It is all working fine for the new products, issue is only for the products which were created before upgradation – Piyush Feb 26 at 19:24
  • Please make sure to assign all websites to a stock before running the indexer. At least all websites with a product assigned. – schnere Apr 8 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.