title: How to add same name product in magento 2?
body: <p>I am uploading product programmatically in Magento2 I have same name product with different SKU but when I run script Magento 2 gives an error because of Url Key  : </p>
  
  <p><code>Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'reine-de-naples-jour-nuit-8998.html-1' for key 'URL_REWRITE_REQUEST_PATH_STORE_ID</code></p>
  
  <p>my script is those we use to save a product programmatically</p>
  
  <pre><code>&lt;?php
  use Magento\Framework\App\Bootstrap;
  include('app/bootstrap.php');
  $bootstrap = Bootstrap::create(BP, $_SERVER);
  $objectManager = $bootstrap-&gt;getObjectManager();
  $objectManager1 = Magento\Framework\App\ObjectManager::getInstance();
  $directoryList = $objectManager1-&gt;get('\Magento\Framework\App\Filesystem\DirectoryList');
  $path = $directoryList-&gt;getPath('media');
  //var_dump($path); die;
  
  
  
  $state = $objectManager-&gt;get('Magento\Framework\App\State');
  $state-&gt;setAreaCode('frontend');
  $myarray = glob("Book2.csv"); 
  usort($myarray, create_function('$a,$b', 'return filemtime($a) - filemtime($b);'));
  if(count($myarray)){
      /*This will create an array of associative arrays with the first row column headers as the keys.*/
      $csv_map = array_map('str_getcsv', file($myarray[count($myarray)-1]));
      array_walk($csv_map, function(&amp;$a) use ($csv_map) {
        $a = array_combine($csv_map[0], $a);
      });
      array_shift($csv_map); # remove column header
      /*End*/
  
      $message = '';
      $count   = 1;
      foreach($csv_map as $data){ 
          //echo '&lt;pre&gt;';print_r($data);exit;
  
  $product = $objectManager-&gt;create('Magento\Catalog\Model\Product');
  $product-&gt;setName(trim($data['Name']));
  $product-&gt;setTypeId('simple');
  $product-&gt;setAttributeSetId(4);
  $product-&gt;setSku(trim($data['model_no']));
  $product-&gt;setURL(trim($data['Name']).trim($data['model_no']));
  $product-&gt;setWebsiteIds(array(1));
  $product-&gt;setVisibility(4);
  $product-&gt;setCreatedAt(strtotime('now'));
  $product-&gt;setPrice(trim($data['price']));
  //$_product-&gt;setShortDescription(trim($data['Short Description'])); // add text attribute
  //$_product-&gt;setDescription(trim($data['Long Description'])); // add text attribute
   $img_url = trim($data['img_big']);
  
                  //$lastWord = substr($img_url, strrpos($img_url, '/') + 1);
  
                  //copy($img_url, 'pub/media/product/');
                  $dir = $directoryList-&gt;getPath('media').'/big/';
                  $imgpath = $dir.$img_url;
                  //echo $imgpath; die;
                  /*$_product-&gt;addImageToMediaGallery($imgpath, array('image','thumbnail','small_image'), false, false); */
                  $product-&gt;addImageToMediaGallery($imgpath, array('image', 'small_image', 'thumbnail'), false, false);
  //$_product-&gt;setImage($imgpath);
  //$_product-&gt;setSmallImage($imgpath);
  //$_product-&gt;setThumbnail($imgpath);
  $product-&gt;setStockData(array(
          'use_config_manage_stock' =&gt; 0, //'Use config settings' checkbox
          'manage_stock' =&gt; 1, //manage stock
          'min_sale_qty' =&gt; 1, //Minimum Qty Allowed in Shopping Cart
          'max_sale_qty' =&gt; 2, //Maximum Qty Allowed in Shopping Cart
          'is_in_stock' =&gt; 1, //Stock Availability
          'qty' =&gt; 100 //qty
          )
      );
  
  $product-&gt;save();
  
      }
  echo'success';
      }
  ?&gt;
  </code></pre>
  
  <p>please suggest how to add Url key to script my script is working fine without the same name </p>