title: Magento 2 Delete all Product Images
body: <p>I need to delete all product images on the site, then re-do the CORRECT import so all the images are correct.</p>
  
  <p>Is there a quick way to delete all images then do a fresh import without duplicated images?</p>
  
  <p>This is my code:</p>
  
  <pre><code>        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
          $product = $objectManager-&gt;create('Magento\Catalog\Model\Product')-&gt;load($id);
          $productRepository = $objectManager-&gt;create('Magento\Catalog\Api\ProductRepositoryInterface');
          $existingMediaGalleryEntries = $product-&gt;getMediaGalleryEntries();
          foreach ($existingMediaGalleryEntries as $key =&gt; $entry)
          {
              unset($existingMediaGalleryEntries[$key]);
          }
          $product-&gt;setMediaGalleryEntries($existingMediaGalleryEntries);
          $productRepository-&gt;save($product);    
  </code></pre>
  
  <p>i get :<br>
  SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (<code>DBname</code>.<code>catalog_product_entity_media_gallery_value</code>, CONSTRAINT <code>CAT_PRD_ENTT_MDA_GLR_VAL_VAL_ID_CAT_PRD_ENTT_MDA_GLR_VAL_ID</code> FOREIGN KEY (<code>value_id</code>) REFERENCES <code>catalog_product_entity_me), query was: INSERT INTO</code>catalog_product_entity_media_gallery_value<code>(</code>value_id<code>,</code>store_id<code>,</code>entity_id<code>,</code>label<code>,</code>position<code>,</code>disabled`) VALUES (?, ?, ?, ?, ?, ?)</p>
  
  <p>Any help would be awesome!</p>