Datenbank Migrationsfehler Titelbild

In unserer Internetagentur migrieren wir aktuell einen alten Magento 1 Shop auf Magento 2.

Für die Migration nutzen wir das Datenbankmigrationstool von Magento. Bei der Nutzung wurde dann folgender Fehler ausgegeben:

 

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

 

Wir haben das Problem wie folgt lösen können (Die Lösung konnten wir hier finden):

 

Als Erstes muss man die folgende Datei öffnen: vendor/magento/data-migration-tool/src/Migration/Step/Eav/Data.php

 

In der Data.php Datei sucht man jetzt nach folgender Funktion:

 


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);
}

 

 

Diese ersetzt man mit der korrigierten Fassung:

 


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);
    }


}

 

Wenn man dies gemacht hat, kann man die Datenmigration problemlos durchlaufen lassen.

 

Am Schluss führt man noch folgende Befehle aus, damit der Shop wie gewünscht funktioniert:

 

bin/magento cache:clean

bin/magento index:reindex

 

Gesehen in unserer Agentur bei der Magento Migration von Version 1 auf 2.