title: Laravel 5 Mysql duplicate entry error
body: <p>I'm using Laravel 5 to insert some entries in to the database but I get the following error:</p>
  
  <blockquote>
    <p>SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'category_id' (SQL: insert into <code>products</code> (<code>product_name</code>, <code>product_price</code>, <code>category_id</code>) values (asdaszzz, 123, 1))</p>
  </blockquote>
  
  <p>As I understand the problem is that the value that I want to add in the category_id table allready exist in other entry, but the thing is that the category_id table is not an UNIQUE key. Below I posted the migration:</p>
  
  <pre><code>public function up()
  {
      Schema::create('products', function($table)
      {
          $table-&gt;increments('id');
          $table-&gt;integer('category_id')-&gt;unsigned();
          $table-&gt;string('product_name', 255)-&gt;unique();
          $table-&gt;decimal('product_price', 10, 4);
          $table-&gt;dateTime('updated_at')-&gt;default(DB::raw('CURRENT_TIMESTAMP'));
      });
  
      Schema::table('products', function($table) {
          $table-&gt;foreign('category_id')-&gt;references('id')-&gt;on('categories');
      });
  }
  </code></pre>