Magento – Key constraint error while importing simple products

import-productsmagento2.2

I am getting an error when I am importing simple products in Magento 2.2.

The error is :

  1. Category " has not been created. URL key for specified store already exists. in row(s): 1 General system exception happened
    Additional data: SQLSTATE[23000]: Integrity constraint violation: 1452
    Cannot add or update a child row: a foreign key constraint fails
    (`acbwqvzgyr`.`catalog_category_product`, CONSTRAINT
    `CAT_CTGR_PRD_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID` FOREIGN KEY
    (`category_id`) REFERENCES `catalog_category_entity` (`entity_id`) ON
    DELETE CASCAD), query was: INSERT INTO `catalog_category_product`
    (`product_id`,`category_id`,`position`) VALUES (?, ?, ?), (?, ?, ?) ON
    DUPLICATE KEY UPDATE `product_id` = VALUES(`product_id`),
    `category_id` = VALUES(`category_id`)

How can I solve this issue?

Best Answer

It seems that your csv has a new category on category column and it is not able to create category due to duplicate name [which is eventually throwing duplicate url issue].

My suggestion would be first create categories separately and them do product import.

Also you can use api to import data where you can check the duplicate url key before you insert a data.

Let me know if you need help on API code.

Related Topic