Data-migration-tool: Integrity Constraint violation for key EAV_ENTITY_ATTRIBUTE_ATTRIBUTE_SET_ID_ATTRIBUTE_ID

Created on 11 Dec 2016  路  23Comments  路  Source: magento/data-migration-tool

I am trying to import data to M 2.1.2 from M 1.9.2.2.
Whenever I run the migration command, i get the error as displayed in the attached screenshot.

screen shot 2016-12-11 at 12 55 55 pm

I feel like the issue is in the eav_entity_attribute data insert.

I am not exactly sure what is wrong in my EAV data. Can you please help me out here?

Thank you

acknowledged bug

Most helpful comment

Problem is here https://github.com/magento/data-migration-tool/blob/921484e78ab292bbaf80e6837aa47bf60c450a28/src/Migration/Step/Eav/Data.php#L642

There is a check

$record->getValue('attribute_id') == $data['customDesignAttributeId']

but should be

($record->getValue('attribute_id') == $data['customDesignAttributeId'] 
|| $record->getValue('attribute_id') == $data['customLayoutAttributeId'])

All 23 comments

Try to restore your DB of Magento 2 to the state it was right after installation and run migration again

Thanks for your response. I just did a fresh Magento 2.1.2 installation and then installed Data Migration tool 2.1.2 and did all settings and mapping, and I am receiving the same error.
I am still not sure what is going on there and why it is generating this error.

Any comments about this issue please?

Thank you

The same issue:

[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '25-303' for key 'EAV_ENTITY_ATTRIBUTE_ATTRIBUTE_SET_ID_ATTRIBUTE_ID'

Dump of the magento1 table: eav_entity_attribute:

--
-- Table structure for table `eav_entity_attribute`
--

DROP TABLE IF EXISTS `eav_entity_attribute`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `eav_entity_attribute` (
  `entity_attribute_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Attribute Id',
  `entity_type_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Entity Type Id',
  `attribute_set_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Attribute Set Id',
  `attribute_group_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Attribute Group Id',
  `attribute_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Attribute Id',
  `sort_order` smallint(6) NOT NULL DEFAULT '0' COMMENT 'Sort Order',
  PRIMARY KEY (`entity_attribute_id`),
  UNIQUE KEY `EAV_ENTITY_ATTRIBUTE_ATTRIBUTE_SET_ID_ATTRIBUTE_ID` (`attribute_set_id`,`attribute_id`),
  UNIQUE KEY `EAV_ENTITY_ATTRIBUTE_ATTRIBUTE_GROUP_ID_ATTRIBUTE_ID` (`attribute_group_id`,`attribute_id`),
  KEY `EAV_ENTITY_ATTRIBUTE_ATTRIBUTE_SET_ID_SORT_ORDER` (`attribute_set_id`,`sort_order`),
  KEY `EAV_ENTITY_ATTRIBUTE_ATTRIBUTE_ID` (`attribute_id`),
  CONSTRAINT `EAV_ENTITY_ATTRIBUTE_ATTRIBUTE_ID_EAV_ATTRIBUTE_ATTRIBUTE_ID` FOREIGN KEY (`attribute_id`) REFERENCES `eav_attribute` (`attribute_id`) ON DELETE CASCADE,
  CONSTRAINT `EAV_ENTT_ATTR_ATTR_GROUP_ID_EAV_ATTR_GROUP_ATTR_GROUP_ID` FOREIGN KEY (`attribute_group_id`) REFERENCES `eav_attribute_group` (`attribute_group_id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=812 DEFAULT CHARSET=utf8 COMMENT='Eav Entity Attributes';
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `eav_entity_attribute`
--

LOCK TABLES `eav_entity_attribute` WRITE;
/*!40000 ALTER TABLE `eav_entity_attribute` DISABLE KEYS */;
INSERT INTO `eav_entity_attribute` VALUES (1,1,1,1,1,10),(2,1,1,1,2,20),(3,1,1,1,3,20),(4,1,1,1,4,30),(5,1,1,1,5,40),(6,1,1,1,6,50),(7,1,1,1,7,60),(8,1,1,1,8,70),(9,1,1,1,9,80),(10,1,1,1,10,25),(11,1,1,1,11,90),(12,1,1,1,12,81),(13,1,1,1,13,115),(14,1,1,1,14,120),(15,1,1,1,15,82),(16,1,1,1,16,83),(17,1,1,1,17,100),(18,1,1,1,18,85),(19,1,1,1,19,86),(20,1,1,1,20,110),(21,1,1,1,21,121),(22,2,2,2,22,10),(23,2,2,2,23,20),(24,2,2,2,24,30),(25,2,2,2,25,40),(26,2,2,2,26,50),(27,2,2,2,27,60),(28,2,2,2,28,70),(29,2,2,2,29,80),(30,2,2,2,30,90),(31,2,2,2,31,100),(32,2,2,2,32,100),(33,2,2,2,33,110),(34,2,2,2,34,120),(35,2,2,2,35,130),(36,2,2,2,36,131),(37,2,2,2,37,132),(38,2,2,2,38,133),(39,2,2,2,39,134),(40,2,2,2,40,135),(41,1,1,1,41,87),(42,1,1,1,42,100),(43,1,1,1,43,110),(44,1,1,1,44,120),(45,3,3,4,45,1),(46,3,3,4,46,2),(47,3,3,4,47,4),(48,3,3,4,48,5),(49,3,3,4,49,6),(50,3,3,4,50,7),(51,3,3,4,51,8),(52,3,3,5,52,10),(53,3,3,5,53,20),(54,3,3,5,54,30),(55,3,3,4,55,12),(56,3,3,4,56,13),(57,3,3,4,57,14),(58,3,3,4,58,15),(59,3,3,4,59,16),(60,3,3,6,60,10),(61,3,3,6,61,30),(62,3,3,6,62,40),(63,3,3,6,63,50),(64,3,3,6,64,60),(65,3,3,4,65,24),(66,3,3,4,66,25),(67,3,3,5,67,40),(68,3,3,5,68,50),(69,3,3,4,69,10),(70,3,3,6,70,5),(71,3,3,6,71,6),(72,3,3,5,72,51),(73,4,4,7,73,10),(74,4,4,7,74,20),(75,4,4,13,75,90),(76,4,4,13,76,100),(77,4,4,7,77,30),(78,4,4,8,78,3),(79,4,4,8,79,4),(80,4,4,8,80,5),(81,4,4,8,81,6),(82,4,4,7,82,70),(83,4,4,9,84,20),(84,4,4,9,85,30),(85,4,4,9,86,40),(86,4,4,10,87,1),(87,4,4,10,88,2),(88,4,4,10,89,3),(89,4,4,10,90,4),(90,4,4,7,91,6),(91,4,4,8,92,7),(92,4,4,7,94,90),(93,4,4,7,95,100),(94,4,4,10,96,5),(95,4,4,7,97,5),(96,4,4,8,98,8),(97,4,4,7,99,80),(98,4,4,14,100,40),(99,4,4,14,101,20),(100,4,4,14,102,30),(101,4,4,11,103,10),(102,4,4,11,104,5),(103,4,4,7,105,80),(104,4,4,11,106,6),(105,4,4,7,107,14),(106,4,4,7,108,15),(107,4,4,7,109,16),(108,4,4,7,110,17),(109,4,4,7,111,18),(110,4,4,7,112,19),(111,4,4,7,113,20),(112,4,4,7,114,110),(113,4,4,7,115,60),(114,4,4,14,116,50),(115,4,4,7,117,31),(116,4,4,7,118,21),(117,4,4,7,119,71),(118,4,4,8,120,9),(119,4,4,15,121,1),(120,3,3,4,122,3),(121,3,3,4,123,17),(122,4,4,9,124,10),(123,4,4,7,125,11),(124,4,4,8,126,10),(125,4,4,8,127,11),(126,4,4,7,128,111),(127,4,4,7,129,112),(128,4,4,7,130,113),(129,4,4,7,131,114),(130,4,4,7,132,32),(131,4,4,7,133,33),(132,4,4,7,134,34),(133,4,4,7,135,35),(134,4,4,7,136,31),(135,4,4,8,137,13),(136,4,4,8,138,14),(137,4,4,8,139,15),(138,4,4,8,140,16),(139,4,4,8,141,17),(140,4,4,8,142,18),(141,4,4,8,143,19),(142,4,4,8,144,20),(143,4,4,7,145,115),(144,4,4,7,146,116),(145,4,4,7,147,117),(146,4,4,7,148,118),(147,4,4,7,149,40),(148,4,4,20,150,10),(149,4,4,20,151,20),(150,4,4,20,152,30),(151,5,5,16,153,1),(152,5,5,16,154,2),(153,1,1,1,155,122),(154,1,1,1,156,123),(155,9,9,21,157,10),(156,9,9,21,158,20),(157,9,9,21,159,30),(158,9,9,21,160,40),(159,9,9,21,161,50),(160,9,9,21,162,60),(161,9,9,21,163,70),(162,9,9,21,164,80),(163,9,9,21,165,90),(164,9,9,21,166,100),(165,9,9,21,167,110),(166,9,9,21,168,120),(167,9,9,21,169,45),(168,9,9,21,170,46),(169,9,9,21,171,47),(170,9,9,21,172,48),(171,9,9,21,173,15),(172,4,4,7,174,120),(173,4,4,10,175,3),(174,3,3,4,176,10),(804,1,1,1,178,100),(806,1,1,1,179,100),(807,3,3,4,180,26),(808,3,3,4,181,27),(809,4,4,9,182,110),(810,4,4,9,183,120),(811,4,4,9,184,130);
/*!40000 ALTER TABLE `eav_entity_attribute` ENABLE KEYS */;
UNLOCK TABLES;

Formatted part of magento1 table 'eav_entity_attribute'

rows: 25-303

Sql request: SELECT * FROM magento1.eav_entity_attribute LIMIT 24, 304;

File with details: attached.

part_of_magento_1_table__eav_entity_attribute__limit_24-304.txt

issue around:

UNIQUE KEY `EAV_ENTITY_ATTRIBUTE_ATTRIBUTE_SET_ID_ATTRIBUTE_ID` (`attribute_set_id`,`attribute_id`)
attribute_set_id and attribute_id concerning to
magento1.eav_entity_attribute
and
magento2.eav_entity_attribute
is not UNIQUE

affected: bin/magento migrate:data /path/to/config.xml

(without -r|--reset argument)

Hi @coresh

Thank you for the details. I have manage to reproduce the "Duplicate entry" error with your eav_entity_attribute dump. Though I got '4-137' as duplicated records still I think it have the same root cause. So internal ticket MAGETWO-62672 was created to fix it

Thanks for creating the internal ticket. Can you confirm if this issue is fixed in 2.1.3?

Thank you

It is not fixed in 2.1.3. The problem is in \Migration\Step\Eav\Data::processDesignEntityAttributes method try to comment/remove it and after migration open original 'Default' attribute set in Magento 2 and find 'Schedule Design Update' group. You should manually add the same group and its attributes to migrated attribute sets from Magento 1

Hi @victor-v-rad, thanks for your complete reaction

@coresh @shy7lo It seems provided dump of eav_entity_attribute table is not enough to understand the whole picture. The EAV step processes the next tables:
eav_attribute_group
eav_attribute_set
eav_attribute
eav_entity_attribute
catalog_eav_attribute
customer_eav_attribute
eav_entity_type
These are also needed to resolve the issue. You can put it here or email me (find email address in my profile https://github.com/victor-v-rad)

Hi Victor,
I have just emailed you dump for all those tables.

Thank you

Same issue here with magento/data-migration-tool": "2.1.3"

Any suggestion on how to get around or fix this?

Hi @diazwatson

I could not reproduce it. The root cause has not been found so far. I suggest you to find differences between the structure attribute sets of your Magento 1 store and Magento 1 in its initial state right after installation. Maybe these differences could have caused the error.
Another way to solve the issue is to send me your DB (if it's not too big and free from sensitive data). I will try to reproduce it on my env. and fix it.

It seems that it depends on some particular attributes, probably for configurable products.
For us is trying to create Baby / Child SS17 attribute set and gives Integrity Constraint violation for key.

Is not that simple to reproduce @victor-v-rad

Note: I am not promoting this module

After wasting a lot of time on this issue and nothing to fix it including the support here, I decided to for this module

https://www.ubertheme.com/magento-extensions-2-x/magento-2-data-migration-pro/

It worked for me and everything was moved smoothly. I know it is expensive, but it is worth time saving and the hard efforts.

Problem is here https://github.com/magento/data-migration-tool/blob/921484e78ab292bbaf80e6837aa47bf60c450a28/src/Migration/Step/Eav/Data.php#L642

There is a check

$record->getValue('attribute_id') == $data['customDesignAttributeId']

but should be

($record->getValue('attribute_id') == $data['customDesignAttributeId'] 
|| $record->getValue('attribute_id') == $data['customLayoutAttributeId'])

Still the same problem on 2.2.2, @alex-borisenko tip did not help me at all. I even have tried to disable the constraint in question, but it fails on next - probably causing domino effect. I don't understand why this issue is closed.

I got this same issue while migrating from 1.7 to 2.2.2
I "fixed" this by renaming the Default attribute set in my Magento 2.2.2 instance back to "Default" (I had changed it's name before migration).
It's a weird solution, I know, but it worked in my case...

This idea came to mind because I noticed that after migration the attribute set IDs were imported from M1 with their original IDs, while the M2 defaults got their IDs "bumped up".
So the default attribute set id from M2 was changed to id = 21.
And in my case the "duplicate entry" was "21-152" which results to attribute_set_id = 21 and attribute_id = 152 which didn't exist in my M1 instance.
Maybe this might help others as well...

in my case database repair tool for source database it was best solution.
https://docs.magento.com/m1/ce/user_guide/magento/database-repair-tool.html

Follow steps and always backup backup

Hope that helps

Still experiencing this in 2.2.6

[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '4-338' for key 'EAV_ENTITY_ATTRIBUTE_ATTRIBUTE_SET_ID_ATTRIBUTE_ID'

Looking at migrateEntityAttributes() in data-migration-tool/blob/2.2.6/src/Migration/Step/Eav/Data.php:

I can see that $this->helper->getSourceRecords($sourceDocName) will add records to the collection that will be added to the destination (m2) database.

Further down I can see that $this->helper->getDestinationRecords('eav_entity_attribute') gets records from the destination(?) and adds them again. From the looks of the code that's what it looks like is going on, but I have a fresh m2 install and there are no records inside the destination (m2) db. So while it _looks_ like this is what's going on. It's hard to believe my perception is the truth.

The error I have for 4-338 pertains to the unique pair of columns attribute_set_id (4) and attribute_id (338). I can confirm in my source (m1) database that there is only one unique pair of this, but within the second foreach loop with $this->helper->getSourceRecords($sourceDocName), another attribute_set_id & attribute_id combination is being added which is throwing this error.

Does anyone have any info on why this is happening and how to fix/prevent it?

Hi @dambrogia

It is hard to figure out why duplicate happens. If it is possible, you can send dump of the next tables

    <group name="documents">
        <document>eav_attribute_group</document>
        <document>eav_attribute_set</document>
        <document>eav_attribute</document>
        <document>eav_entity_attribute</document>
        <document>catalog_eav_attribute</document>
        <document>customer_eav_attribute</document>
        <document>eav_entity_type</document>
    </group>

To my email. I will try to migrate and reproduce the issue

@victor-v-rad thank you for the response. It turned out that @alex-borisenko answer was the solution. attribute_id 338 was the layout attribute_id. Adding that extra conditional to my if statement prevented the duplicate 4-338 pair from being added.

Thanks for checking in on my status. FWIW I'm using the 2.2.6 migration tool.

This issue appears after creating a new attribute set in M2 based on "Default" attribute set before migration. It is recommended to migrate to the clean M2 store (without new entities). Anyway the fix from @alex-borisenko comment works.

My problem was solved so I'm a happy camper. But just a heads up I was receiving this error on a fresh m2 install. Anyways, thanks for your help and support. It is much appreciated!

Was this page helpful?
0 / 5 - 0 ratings