At our web agency, we are currently migrating an old Magento 1 store to Magento 2.
For the migration, we are using Magento's database migration tool. When using it, the following error was displayed:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) ORDER BY `entity_attribute_id` ASC LIMIT 162' at line 1, query was: SELECT `eav_entity_attribute`.* FROM `eav_entity_attribute` WHERE (`entity_attribute_id` >= 0) AND (attribute_id IN ()) ORDER BY `entity_attribute_id` ASC LIMIT 162
We were able to solve the problem as follows (we found the solution here):
First, open the following file: vendor/magento/data-migration-tool/src/Migration/Step/Eav/Data.php
In the Data.php file, look for the following function:
private function migrateCustomEntityAttributes()
{
$this->progress->advance();
$sourceDocName = 'eav_entity_attribute';
$destinationDocument = $this->destination->getDocument(
$this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE)
);
$recordsToSave = $destinationDocument->getRecords();
$customAttributeIds = $this->modelData->getCustomAttributeIds();
$customEntityAttributes = $this->source->getRecords(
$sourceDocName,
0,
$this->source->getRecordsCount($sourceDocName),
new \Zend_Db_Expr(sprintf('attribute_id IN (%s)', implode(',', $customAttributeIds)))
);
foreach ($customEntityAttributes as $record) {
$record['sort_order'] = $this->getCustomAttributeSortOrder($record);
$record['attribute_group_id'] = $this->mapAttributeGroupIdsSourceDest[$record['attribute_group_id']];
$record['entity_attribute_id'] = null;
$destinationRecord = $this->factory->create(['document' => $destinationDocument, 'data' => $record]);
$recordsToSave->addRecord($destinationRecord);
}
$this->saveRecords($destinationDocument, $recordsToSave);
}
Replace it with the corrected version:
private function migrateCustomEntityAttributes()
{
$this->progress->advance();
$sourceDocName = 'eav_entity_attribute';
$destinationDocument = $this->destination->getDocument(
$this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE)
);
$recordsToSave = $destinationDocument->getRecords();
$customAttributeIds = $this->modelData->getCustomAttributeIds();
```
if ($customAttributeIds) // Added by Heider to ensure that we process ONLY if there are new ATTRs
{
$customEntityAttributes = $this->source->getRecords(
$sourceDocName,
0,
$this->source->getRecordsCount($sourceDocName),
new \Zend_Db_Expr(sprintf('attribute_id IN (%s)', implode(',', $customAttributeIds)))
);
foreach ($customEntityAttributes as $record) {
$record['sort_order'] = $this->getCustomAttributeSortOrder($record);
$record['attribute_group_id'] = $this->mapAttributeGroupIdsSourceDest[$record['attribute_group_id']];
$record['entity_attribute_id'] = null;
$destinationRecord = $this->factory->create(['document' => $destinationDocument, 'data' => $record]);
$recordsToSave->addRecord($destinationRecord);
}
$this->saveRecords($destinationDocument, $recordsToSave);
}
```
}
Once this has been done, the data migration can be completed without any problems.
Finally, run the following commands so that the store works as expected:
bin/magento cache:clean
bin/magento index:reindex
We encountered this issue at our agency during a Magento 1 to Magento 2 migration.
