How to fix Magento 2 item with the same ID already exists error

- E-Commerce, Magento 2

Magento 2 item with the same ID already exists error

In the following post, we shed light on how to fix the “Item (Magento\…) with the same ID already exists“ error in Magento 2. The problem occurs when you delete a product manually, and the product with this entity_id is no longer available on either the frontend or backend. You can find more information about other Magento 2 errors here: Magento 2 Developer’s Cookbook

'

How to fix Magento 2 item with the same ID already exists error

The system informs you about the error as follows:

Magento 2 item with the same ID already exists error

What is the reason for the issue? As we’ve previously mentioned, you have to delete a product to face the warning. If some information about a product’s ID is not removed, you see the message displayed above.

It is usually displayed when you try to create a data feed of products. 

Solution 1

Duplicate entry in cataloginventory_stock_item is a common source for this error. It is possible to search for an ID if you have one. To find all duplicate product entity_ids, simply use the following SQL statement:

Find duplicates and delete them.

Solution 2

If you get the error without any duplicate stocks and have no idea about this ID, you need to use a MySQL database tool (such as Navicat) to search all tables for this ID. Navicat provides the following output:

Magento 2 item with the same ID already exists error

The deleted product may be assigned to a category, causing the issue. Delete the wrong line to fix the issue. The problem is caused by a Magento 2 bug related to deleting products and their category assignments.

Solution 3

Use Improved Import & Export Magento 2 extension to delete or update existing products. Thus, you will keep your database clear. 

Go to System->Improved Import/Export->Import Jobs and hit the “Add New Job” button.

Magento 2 item with the same ID already exists error

In General Settings, enable the job, specify its title, choose the manual run frequency (you can create a schedule of updates), select a language (locale), and enable/disable the following features depending on your business needs:

  • Generate Unique Url if Duplicate;
  • Re-Index after Import; 
  • Send email from new tracks.

Magento 2 item with the same ID already exists error

In Import Settings, enable/disable API (depending on what your import source is), choose Products in the Entity dropdown, and select a platform.

You can also enable/disable the following features:

  • Clear Attribute Values – empty/deselect values for ALL optional attributes you are importing;
  • Remove Product Association – remove product associations for grouped products;
  • Remove Product Website  -remove any old websites assigned to products;
  • Remove Product Categories – remove old categories assigned to products;
  • Remove All Images – remove all existing image allocation from the database (not from the directory);
  • Remove Related Products – replace old related products with new ones from the import file.

Magento 2 item with the same ID already exists error

In Import Behavior, select Add/Update, Only Update, Only Add, Replace, or Delete from the dropdown, choose a validation strategy, specify the maximum possible number of errors, and set separators.

Magento 2 item with the same ID already exists error

In Import Source, select CSV as your import file type (or choose another standard if your data file is not CSV). Next, specify your import source. You can import a data file from a server, Dropbox account, URL, or upload it directly. In the case of Dropbox, specify a file path, access token, and remote images directory. Enable/disable the following features depending on your business needs:

  • Use Image Import Source;
  • Do you want to remove current mappings?

Magento 2 item with the same ID already exists error

Validate the data file with products. If it contains attributes that are not supported by Magento 2, you can apply mapping. We will describe this feature further in this article. 

To start the import process, hit “Save & Run” in the top right corner of the screen. For further information about product import in Magento 2, check this article: The Complete Guide to Magento 2 Product Import / Export. Or follow the link below and contact our support:

Get Improved Import & Export Magento 2 Extension

Improved Import & Export Features

Magento 2 item with the same ID already exists error

Now, let’s pay a little bit more attention to the features of the Improved Import & Export extension. The tool is designed to turn your Magento 2 admin into a central hub where you control all integrations; therefore, it is much more potent than any import/export solution currently available on the market. Even the default transfer tools of Magento 2 Commerce don’t offer anything similar. 

The extension provides several ways of moving products to and from your e-commerce website, including a direct connection between the two systems. As an admin, you can manage all integrations right in the backend interface. And as it was mentioned above, the plugin allows automating all product import and export processes. Let’s start the exploration with this feature.

Automated Import & Export Processes

The Improved Import & Export Magento 2 extension offers two different ways of automatic product data import and export: schedules and event-based triggers. The principle behind both mechanisms is described below. You only have to configure your import/export job, and the extension does everything for you. Let’s see how schedules work.

Schedules

With the Improved Import & Export Magento 2 extension, you can use the default cron syntax to create export schedules moving Magento 2 products to a remote platform. The module provides the ability to specify any custom intervals so that you can create a schedule suitable for your specific business needs. At the same time, you can select one of the predefined intervals, which are also fully customizable – just like in the product export example above. Select a value that seems to be suitable and modify it according to your business requirements.

And don’t forget about the opportunity to create import and export profiles which have no schedules. If you only need to move data once, migrating to Magento 2, there is no need to schedule multiple processes.

Another cool feature related to schedules is the ability to launch every profile manually. For instance, you need to transfer products to an external system every day at 6 PM, but no new products have been updated. You can quickly move them manually to an eternal system after changes are applied.

With the Improved Import & Export Magento 2 extension, it is possible to transfer all product data to and from your database manually within just a few clicks. It is no longer necessary to wait for the next planned import/export event. As for the configuration of a schedule, it looks as follows:

Magento 2 item with the same ID already exists error

Events

Event-based triggers represent the second way of automating data transfers in Magento 2. The Improved Import & Export extension enables real-time updates based on them. Create and configure a trigger specifying conditions to synchronize two systems right after a particular action takes place. For further information, check this article: How to Run Magento 2 Import or Export After Specific System Event or Process.

Advanced Mapping Features

The following chapter discusses another essential aspect of the Improved Import & Export Magento 2 extension – the ability to solve problems caused by different attribute standards. Our module provides several exclusive mapping features that dramatically simplify both import and export procedures.

Mapping Presets

The Improved Import & Export Magento 2 extension offers a very straightforward way of matching external attributes to ones used internally. You get a series of mapping presets – predefined mapping schemes that provide the ability to implement attribute matching in a few clicks. After creating and configuring a new job, choose a suitable preset in the mapping section of your new profile. Next, the Improved Import & Export Magento 2 extension will do all the work for you.

Instead of looking for third-party attributes in your products file, you let our module analyze the input data and match all third-party designations to the internal ones. Any manual interactions with data files are eliminated. Here is how everything happens in the admin:

Magento 2 item with the same ID already exists error

Matching Interface

If there is no preset suitable for your integration or you want to make an import/export file suitable for third-party requirements manually, utilize the matching interface of the Improved Import & Export Magento 2 extension. It lets you map attributes by yourself, but your admin replaces a third-party editor. The procedure is fast and intuitive: select an entity, choose a system attribute, and specify the corresponding external one in front of it as shown below:

In the grid above, there is also the third column – “Default Value” –  where you can specify hardcoded (default) values, which are attribute values automatically provided to every item related to the attribute. It is handy when, for instance, you import products from multiple store views to a single one.

Magento 2 item with the same ID already exists error

Filters

Now when you know how to apply mapping and use hardcoded (default) values, we’d like to describe another feature that lets you export Magento 2 products to a remote system – filters. Follow these steps to master the tool:

  • Click the ‘Add Filter’ button;
  • Select an entity;
  • Select a system attribute that will be used as a basis of a new filter;
  • Specify parameters applied for filtering;
  • Repeat the previous steps to create more filters.

Note that parameters applied for filtering vary, depending on the chosen attribute. Everything is intuitive and straightforward:

Magento 2 item with the same ID already exists error

Attribute Values Mapping

Besides, the Improved Import & Export Magento 2 extension provides the ability to match attribute values when you transfer products. Since incorrect values may prevent import processes or may not be accepted by third-party systems, it is essential to replace all unsupported designations with the proper ones. Unfortunately, the default Magento tools don’t let you do that.

However, you can choose a third-party designation and specify a corresponding internal one in front of it with Improved Import & Export. Repeat matching until no external values are left. For further information, read this article: Attribute Values Mapping.

Attribute Values Editing

The Improved Import & Export Magento 2 module lets you not only map attribute values but also edit them in bulk. The extension provides the following rules that can be combined and applied to multiple values simultaneously:

  • Add a prefix to multiple attribute values;
  • Add a suffix to multiple attribute values;
  • Split multiple attribute values;
  • Merge multiple attribute values.

Note that the module provides the ability to create various conditions to increase the efficiency of editing. For further information, check this article: How to Modify Attribute Values During Import and Export in Magento 2.

Category Mapping

Another feature of the Improved Import & Export Magento 2 extension that simplifies the way you import product data from any source is category mapping. It is especially useful when you transfer information from third-party catalogs that have a unique structure.

The Improved Import & Export extension provides the ability to match external product categories to ones used internally. You apply all the changes in a single place of your admin instead of editing multiple products afterward. The process looks as follows:

Magento 2 item with the same ID already exists error

In addition to mapping, it also allows creating new categories on the fly. The Improved Import & Export Magento 2 module lets you select a parent category and specify a new one related to it. Both features are described here: Category Mapping.

Attributes On The Fly

Another feature that dramatically simplifies product import processes is the ability to create attributes on the fly. If an update file doesn’t include all the necessary data, our module allows using the following general form to specify all parameters used to get all missing attributes automatically:

Attribute|attribute_property_name:attribute_property_value|…

The procedure is described in more detail here: Product attributes import.

Extended Connectivity Options

As mentioned above, the Improved Import & Export Magento 2 extension allows extending the default opportunities related to product data transfers.

Multiple File Standards

You are no longer limited to CSV files – the only standard supported by Magento. The Improved Import & Export Magento 2 extension lets you use XML, JSON, ODS, and Excel files instead. Thus, the necessity to convert product data files of these standards into CSV and vice versa is completely eliminated! You can always apply all the features described above to any of these file types.

Multiple File Sources

And the vital improvement that enables product file import/export is support for multiple sources. The Improved Import & Export Magento 2 extension lets you leverage several different connection options:

  • FTP/SFTP. Transfer data files using a local or remote server.
  • Dropbox. Use a Dropbox account to establish a connection between the two systems. Alternatively, you can rely on Box, OneDrive, Google Drive, iCloud, and Amazon Drive.
  • URL. A direct URL can be used to import a data file as well.

In case an update file is compressed, you don’t need to extract it before the import. The Improved Import & Export Magento 2 extension will do everything for you!

Magento 2 item with the same ID already exists error

Alternative Ways of Import & Export

Note that the alternative ways of import and export are not represented in Magento 2 by default. However, direct API connections are the only way to enable the Magento 2 integration with most external platforms.

As we’ve mentioned above, the Improved Import & Export extension provides the ability to leverage REST as well as other APIs if necessary for the Magento 2 ANY PLATFORM synchronization. For instance, it works with SOAP and GraphQL. Note that all API connections support other extension’s features.

As for the intermediary services, you can rely on Google Sheets, Office 365 Excel, and Zoho Sheet transferring product data to your e-commerce store. The following image shows how to use Google Sheets to move products to Magento 2:

Magento 2 item with the same ID already exists error

And of course, the Improved Import & Export extension opens completely new possibilities with support for WSDL and WADL.

The video below displays other details of our extension:

Conclusion

For further information on how to fix the “Item with the same ID already exists” Magento 2 error follow this link: Magento 2 – Item with the same ID already exists. If you want to prevent the problem, use our extension when updating a product database:

Get Improved Import & Export Magento 2 Extension

'