Is it possible insert not update (update is simple) image roles (base, small , thumnail) in catalog_product_entity_varchar table if in the table missing attribute row for the products images

1 Answer 1


Yes, it is possible to insert new rows in the catalog_product_entity_varchar table for the product image attributes if they are missing.

You can achieve this by creating a custom script or module that queries the product collection and checks if the catalog_product_entity_varchar table has an entry for the base_image, small_image, and thumbnail attributes. If any of these attributes are missing, you can use the following code to insert new rows:

    // Load product collection
    $products = \Magento\Framework\App\ObjectManager::getInstance()->create('Magento\Catalog\Model\ResourceModel\Product\Collection');

    // Loop through products and check if image attributes are set
    foreach ($products as $product) {
        $productId = $product->getId();
        $storeId = $product->getStoreId();

        // Check if base_image attribute is set
        $baseImageAttr = $product->getResource()->getAttribute('base_image');
        if (!$baseImageAttr->getFrontend()->getValue($product)) {
            $product->addImageToMediaGallery('path/to/image.jpg', array('image', 'small_image', 'thumbnail'), true, false);

This code checks if the base_image attribute is set for each product and if it's not, it adds the image to the media gallery and sets the image, small_image, and thumbnail roles for the image.

Note: It's recommended to use a module or custom script for this rather than directly inserting records in the database table, as direct database manipulation can be risky and cause issues.

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.