Magento2 import csv file get error interity constraint
-
08-10-2020 - |
Question
Im upload bulk products successfully afterthat im delete all products use this command in my catlog
DELETE FROM catalog_product_entity;
afterthat im try to re upload products im getting an error like this
General system exception happened
Additional data: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'ceratizit-11759716-spun-120308-inserts-for-turning.html-1' for key 'URL_REWRITE_REQUEST_PATH_STORE_ID', query was: INSERT INTO `url_rewrite` (`redirect_type`,`is_autogenerated`,`metadata`,`description`,`entity_type`,`entity_id`,`request_path`,`target_path`,`store_id`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?),
La solution
It is due to you have not removed entries for the product URL Keys from url_rewrite table. Moreover it is not a proper way to delete a product because by doing this you are just removing entries from main product table where as all other tables will have data related to those products and it will duplicate data in related tables. Apart from that your table size also will increase due to dumping of data which is unused as you delete entries from main table.
You can check following link to delete a data from DB.
Magento 2: How to truncate customers, products, reviews and orders table
Autres conseils
Please take backup of database before working- follow the following steps-
1- open your database and truncate tables using command
TRUNCATE TABLE `catalog_url_rewrite_product_category`;
TRUNCATE TABLE `url_rewrite`;
2- perform you CSV import
3- Generate new URL using following extension
https://github.com/Iazel/magento2-regenurl