During import I get errors like

PHP Fatal error:  Uncaught exception 'PDOException' with message 
    'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or 
    update a child row: a foreign key constraint fails   
    (`foo`.`catalog_product_link`, CONSTRAINT 
    (`linked_product_id`) REFERENCES `catalog_product_entity` (`entity_id`)' 
    in lib/Zend/Db/Statement/Pdo.php:228

I already changed Mage_ImportExport_Model_Import_Entity_Product::_saveLinks() for debugging the single inserts:

        if ($linkRows) {
            foreach($linkRows as $row) {

And now I get linked_product_id' cannot be null'

The full import stops because of this error.


You can add some debug code in \Mage_ImportExport_Model_Import_Entity_Product::_saveLinks to track down this problem and to avoid, that the full import stops:

    if ((isset($this->_newSku[$linkedSku]) || isset($this->_oldSku[$linkedSku]))
            && $linkedSku != $sku) {
        if (isset($this->_newSku[$linkedSku])) {
            $linkedId = $this->_newSku[$linkedSku]['entity_id'];
        } else {
            $linkedId = $this->_oldSku[$linkedSku]['entity_id'];
        $linkKey = "{$productId}-{$linkedId}-{$linkId}";

// [BEGIN CHANGE] - Comment: Debug
        if ($linkedId == null) {
                new Exception(
                    sprintf('Debug - WARNING: Orphaned link skipped: From SKU %s (ID %d) to SKU %s, Link type id: %d',
                        $sku, $productId, $linkedSku, $linkId)
// [END]

This will log an exception with detailed information about the products and links the error is about.

In my case there were errors with the products referenced as related products. So those products were skipped during import and Magento generated links to "null"

Magento 2 PullRequest

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.