title: PDOException::("SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'Laptop1' for key 'products_name_unique'")
body: <p>This is My ProductsTableSeeder
  I create the products into products table and relationship with cateogries
  creating category_product table and adding foreign key to that.</p>
  
  <p>I have an error when I migrate and seed the data it says duplicate.
  How do I fix it?</p>
  
  <pre><code>use App\Product;
  use Illuminate\Database\Seeder;
  
  class ProductsTableSeeder extends Seeder
  {
      /**
       * Run the database seeds.
       *
       * @return void
       */
      public function run()
      {
          //
  
          //Product::truncate();
  
          for($i = 1; $i &lt;= 10; $i++){
              Product::updateOrCreate([
                  'name'=&gt; 'Laptop'.$i,
                  'slug' =&gt; 'laptop'.$i,
                  'details' =&gt; [13,14,15][array_rand([13,14,15])].'inch,'.[1,2,3][array_rand([1,2,3])].'TB SSD,32GB RAM',
                  'price' =&gt; rand(1500,3000),
                  'description' =&gt; 'Lorem'.$i.' ipsum dolor sit amet, consectetur adipiscing elit. Maecenas fermentum. laoreet turpis, nec sollicitudin dolor cursus at. Maecenas aliquet, dolor a faucibus efficitur, nisi tellus cursus urna, eget dictum lacus turpis.',
                  ])-&gt;categories()-&gt;attach(1);
          }
          $product = Product::find(1)-&gt; categories()-&gt;attach(2); 
  }
  </code></pre>
  
  <p>This is Product Table.</p>
  
  <pre><code>  public function up()
      {
          Schema::create('products', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;string('name')-&gt;unique();
              $table-&gt;string('slug')-&gt;unique();
              $table-&gt;string('details')-&gt;nullable();
              $table-&gt;float('price');
              $table-&gt;text('description');
              //$table-&gt;integer('category_id');
              $table-&gt;timestamps();
          });
      }
  </code></pre>
  
  <p>This is Category Table.</p>
  
  <pre><code>public function up()
      {
          Schema::create('categories', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;string('name')-&gt;unique();
              $table-&gt;string('slug')-&gt;unique();
              $table-&gt;timestamps();
          });
      }
  </code></pre>
  
  <p>This is relationship table.</p>
  
  <pre><code>public function up()
      {
          Schema::create('category_product', function (Blueprint $table) {
              $table-&gt;increments('id');
  
              $table-&gt;integer('product_id')-&gt;unsigned()-&gt;nullable();
              $table-&gt;foreign('product_id')-&gt;references('id')-&gt;on('products')-&gt;onDelete('cascade');
  
              $table-&gt;integer('category_id')-&gt;unsigned()-&gt;nullable();
              $table-&gt;foreign('category_id')-&gt;references('id')-&gt;on('categories')-&gt;onDelete('cascade');
  
              $table-&gt;timestamps();
          });
      }
  </code></pre>