Magento – product not saving after upgrading to Magento 2.3

adminmagento2magento2.3multi-source-inventory

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?

Best Answer

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.

Related Topic