0

I deleted all the products and categories via

SQL queries (i used this answer https://magento.stackexchange.com/a/283404/73525 )

while saving new product i got error Unable to save Stock Item

Exception.log

[2019-07-27 07:09:08] main.CRITICAL: Unable to save Stock Item {"exception":"[object] (Magento\\Framework\\Exception\\CouldNotSaveException(code: 0): Unable to save Stock Item at /home/goodma20/project1.com/vendor/magento/module-catalog-inventory/Model/Stock/StockItemRepository.php:183, Zend_Db_Statement_Exception(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`goodma20_test25072019`.`mg_cataloginventory_stock_item`, CONSTRAINT `MG_CATINV_STOCK_ITEM_STOCK_ID_CATINV_STOCK_STOCK_ID` FOREIGN KEY (`stock_id`) REFERENCES `mg_cataloginventory_stock` (`sto), query was: INSERT INTO `mg_cataloginventory_stock_item` (`product_id`, `stock_id`, `qty`, `min_qty`, `use_config_min_qty`, `is_qty_decimal`, `backorders`, `use_config_backorders`, `min_sale_qty`, `use_config_min_sale_qty`, `max_sale_qty`, `use_config_max_sale_qty`, `is_in_stock`, `low_stock_date`, `notify_stock_qty`, `use_config_notify_stock_qty`, `manage_stock`, `use_config_manage_stock`, `stock_status_changed_auto`, `use_config_qty_increments`, `qty_increments`, `use_config_enable_qty_inc`, `enable_qty_increments`, `is_decimal_divided`, `website_id`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '2019-07-27 07:09:08', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) at /home/goodma20/project1.com/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 (`goodma20_test25072019`.`mg_cataloginventory_stock_item`, CONSTRAINT `MG_CATINV_STOCK_ITEM_STOCK_ID_CATINV_STOCK_STOCK_ID` FOREIGN KEY (`stock_id`) REFERENCES `mg_cataloginventory_stock` (`sto) at /home/goodma20/project1.com/vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:228)"} []
[2019-07-27 07:22:56] main.CRITICAL: No such entity with id = 6300 {"exception":"[object] (Magento\\Framework\\Exception\\NoSuchEntityException(code: 0): No such entity with id = 6300 at /home/goodma20/project1.com/vendor/magento/framewo
0

fixed issue by this

query

insert into `cataloginventory_stock`(`stock_id`,`website_id`,`stock_name`) values (1,0,'Default');

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.