0

i am following this link :

Find entity_id & attribute_id of an attribute

I used this sql query :

INSERT INTO catalog_product_entity_varchar ( entity_type_id, attribute_id, store_id, entity_id, value) 
SELECT 10, 1021, 1, entity_id, value
FROM catalog_product_entity_int
WHERE attribute_id = 1021;

but i got error in the image :enter image description here

@Marius suggested to use "ON DUPLICATE KEY UPDATE" . I have no idea about this. when i googled it, i got some solution, but that did't worked.

please give me the updated query using ON DUPLICATE KEY UPDATE

1 Answer 1

1

Bellow script run on magento root folder

<?php
require_once('app/Mage.php');
Mage::app('default');

class AR
{
    public function index()
    {
        $writeAdapter = Mage::getSingleton('core/resource')->getConnection('core_write');
        $readAdapter = Mage::getSingleton('core/resource')->getConnection('core_read');
        $resultAll = $readAdapter->fetchAll('SELECT `entity_type_id`,`attribute_id` ,`store_id`, `entity_id`, `value` FROM `catalog_product_entity_int` WHERE `attribute_id` =1021');
        foreach($resultAll as $result) {
             $writeAdapter->query('DELETE FROM `catalog_product_entity_varchar` WHERE `catalog_product_entity_varchar`.`attribute_id` =1021;');
            $query = "INSERT INTO `catalog_product_entity_varchar` (`value_id`, `entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES (NULL, '".$result['entity_type_id']."', '".$result['attribute_id']."', '".$result['store_id']."', '".$result['entity_id']."', '".$result['value']."');";
         $writeAdapter->query($query);
        }

        echo 'Attribute values are updated.';  


    }

}

$obj = new AR();
$obj->index();
?>
12
  • but i got this error : prntscr.com/9t8weo Commented Jan 22, 2016 at 6:25
  • can you share error?
    – Abdul
    Commented Jan 22, 2016 at 6:28
  • Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '213-1021-0' for key 'UNQ_CAT_PRD_ENTT_VCHR_ENTT_ID_ATTR_ID_STORE_ID'' in /var/www/html/vikas/lib/Zend/Db/Statement/Pdo.php:228 Stack trace: Commented Jan 22, 2016 at 6:28
  • updated ans pls check now..
    – Abdul
    Commented Jan 22, 2016 at 6:32
  • it showing blank page, is i have to wait for some more time ? Commented Jan 22, 2016 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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