title: how to use foreign key in laravel 5.1 migration
body: <p>I need to use foreign key for my database but I can't do this, after run migration command in command line, I get this error :</p>
  
  <blockquote>
    <p>[Illuminate\Database\QueryException]   SQLSTATE[HY000]: General error:
    1215 Cannot add foreign key constraint (SQL: alter table <code>samples</code> add
    constraint s   amples_supplier_id_foreign foreign key (<code>supplier_id</code>)
    references <code>suppliers</code> (<code>id</code>))</p>
    
    <p>[PDOException]   SQLSTATE[HY000]: General error: 1215 Cannot add
    foreign key constraint</p>
  </blockquote>
  
  <p>Samples migration :</p>
  
  <pre><code>Schema::create('samples', function (Blueprint $table) {
              $table-&gt;Increments('id',true);
              $table-&gt;string('variety',50);
              $table-&gt;integer('supplier_id')-&gt;unsigned();
              $table-&gt;foreign('supplier_id')-&gt;references('id')-&gt;on('suppliers');
              $table-&gt;string('lot_number');
              $table-&gt;date('date');
              $table-&gt;integer('amount');
              $table-&gt;integer('unit_id')-&gt;unsigned();
              $table-&gt;foreign('unit_id')-&gt;references('id')-&gt;on('unit');
              $table-&gt;string('technical_fact');
              $table-&gt;string('comments');
              $table-&gt;string('file_address');
              $table-&gt;integer('category_id')-&gt;unsigned();
              $table-&gt;foreign('category_id')-&gt;references('id')-&gt;on('category');
              $table-&gt;timestamps();
          });
  </code></pre>
  
  <p>Supplier migration : </p>
  
  <pre><code>Schema::create('suppliers', function (Blueprint $table) {
              $table-&gt;Increments('id',true);
              $table-&gt;string('supplier',50);
              $table-&gt;timestamps();
          });
  </code></pre>
  
  <p>I try to that with new migration for samples, but unsuccessful :</p>
  
  <pre><code>Schema::create('samples', function (Blueprint $table) {
                  $table-&gt;Increments('id',true);
                  $table-&gt;string('variety',50);
                  $table-&gt;integer('supplier_id')-&gt;unsigned();
                  $table-&gt;string('lot_number');
                  $table-&gt;date('date');
                  $table-&gt;integer('amount');
                  $table-&gt;integer('unit_id')-&gt;unsigned();
                  $table-&gt;string('technical_fact');
                  $table-&gt;string('comments');
                  $table-&gt;string('file_address');
                  $table-&gt;integer('category_id')-&gt;unsigned();
                  $table-&gt;timestamps();
          });
  
          Schema::table('samples', function($table) {
              $table-&gt;foreign('supplier_id')-&gt;references('id')-&gt;on('suppliers');
              $table-&gt;foreign('unit_id')-&gt;references('id')-&gt;on('unit');
              $table-&gt;foreign('category_id')-&gt;references('id')-&gt;on('category');
          });
  </code></pre>
  
  <p>I try to fix length of the primary key to 10, but unsuccessful again</p>