0

I was using the Magento 2.3.2 normally, but since I updated to Magento 2.3.3 I'm not able to create a new product anymore. I'm receiving this message below.

The stock item was unable to be saved. Please try again.

Magento 2 The stock item was unable to be saved

My exception.log is logging this message:

[2019-11-06 17:30:42] 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 /Users/rafael/dev/mystoremagento/vendor/magento/module-catalog-inventory/Model/Stock/StockItemRepository.php:187, Magento\Framework\Exception\CouldNotSaveException(code: 0): Could not save Source Item at /Users/rafael/dev/mystoremagento/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 (mystoremagento.inventory_source_item, CONSTRAINT INVENTORY_SOURCE_ITEM_SOURCE_CODE_INVENTORY_SOURCE_SOURCE_CODE FOREIGN KEY (source_code) REFERENCES inventory_source (source_code) ), query was: INSERT INTO inventory_source_item (source_code, sku, quantity, status) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE quantity = VALUES(quantity), status = VALUES(status) at /Users/rafael/dev/mystoremagento/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:110, PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (mystoremagento.inventory_source_item, CONSTRAINT INVENTORY_SOURCE_ITEM_SOURCE_CODE_INVENTORY_SOURCE_SOURCE_CODE FOREIGN KEY (source_code) REFERENCES inventory_source (source_code) ) at /Users/rafael/dev/mystoremagento/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:91)"} []

Even doing these tests it doesn't work:

  • Disabling all third-party module
  • Running the install process (using the same DB)
  • Exporting and importing the DB
0

I fixed it removing all Magento MSI modules running these commands:

composer require yireo/magento2-replace-inventory:2.3.*
bin/magento s:upgrade
bin/magento deploy:mode:set developer
bin/magento setup:static-content:deploy -f
bin/magento setup:di:compile
bin/magento cache:flush
bin/magento index:reindex
| improve this answer | |

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.