7

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 '19 at 5:01
  • did you checked after indexing ? – Aasim Goriya Jan 21 '19 at 5:09
  • Issue seems must be because of reindexing, please reset reindex and re-index again. – Aasim Goriya Jan 21 '19 at 5:11
  • @AasimGoriya I tried reset and reindex again, still same result – Piyush Jan 21 '19 at 5:18
  • I am facing a similar issue after upgrading 2.2.6 to 2.3.1. – Senthilnathan Gopal Jun 11 '19 at 11:20
4
+100

Simple solution if you are not planning to use MSI you can simply disable all modules related to it by using below

php bin/magento module:disable -f Magento_Inventory Magento_InventoryAdminUi Magento_InventoryApi Magento_InventoryBundleProduct Magento_InventoryBundleProductAdminUi Magento_InventoryCatalog Magento_InventorySales Magento_InventoryCatalogAdminUi Magento_InventoryCatalogApi Magento_InventoryCatalogSearch Magento_InventoryConfigurableProduct Magento_InventoryConfigurableProductAdminUi Magento_InventoryConfigurableProductIndexer Magento_InventoryConfiguration Magento_InventoryConfigurationApi Magento_InventoryGroupedProduct Magento_InventoryGroupedProductAdminUi Magento_InventoryGroupedProductIndexer Magento_InventoryImportExport Magento_InventoryIndexer Magento_InventoryLowQuantityNotification Magento_InventoryLowQuantityNotificationAdminUi Magento_InventoryLowQuantityNotificationApi Magento_InventoryMultiDimensionalIndexerApi Magento_InventoryProductAlert Magento_InventoryReservations Magento_InventoryReservationsApi Magento_InventoryCache Magento_InventorySalesAdminUi Magento_InventorySalesApi Magento_InventorySalesFrontendUi Magento_InventoryShipping Magento_InventorySourceDeductionApi Magento_InventorySourceSelection Magento_InventorySourceSelectionApi Magento_InventoryShippingAdminUi Magento_InventoryDistanceBasedSourceSelectionAdminUi Magento_InventoryDistanceBasedSourceSelectionApi Magento_InventoryElasticsearch Magento_InventoryExportStockApi Magento_InventoryReservationCli Magento_InventoryExportStock Magento_CatalogInventoryGraphQl Magento_InventorySetupFixtureGenerator

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.

enter image description here

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.

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 '19 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 '19 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 '19 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 '19 at 14:13
0

just switch from ElasticSearch (6.0 or regular) to MySQL search and it will solve your issue

hope this helps!

0

Try to change Index product price into Update By Schedule.

enter image description here

I found that plugin tries to reindex prices in trunsaction.

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.