title: Laravel migration (errno: 150 "Foreign key constraint is incorrectly formed")
body: <p>I have an orders table and a have a <code>sell_shipping_labels</code> which references <code>orders.id</code> as a foreign. However when I run the Laravel migration I get the dreaded error code:</p>
  
  <blockquote>
    <p>[Illuminate\Database\QueryException]<br>
      SQLSTATE[HY000]: General error: 1005 Can't create table <code>cheapbooks_test</code>.<code>#sql-b5b_b2a</code> (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table <code>sell_shipping_labels</code> add constraint <code>sell_shipping_labels_order_id_foreign</code> foreign key (<code>order_id</code>) references <code>orders</code> (<code>id</code>))                                                     </p>
    
    <p>[Doctrine\DBAL\Driver\PDOException]<br>
      SQLSTATE[HY000]: General error: 1005 Can't create table <code>cheapbooks_test</code>.<code>#sql-b5b_b2a</code> (errno: 150 "Foreign key constraint is incorrectly formed") </p>
  </blockquote>
  
  <p>This is my <code>orders</code> table schema:</p>
  
  <pre><code>   Schema::create('orders', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;integer('user_id');
          $table-&gt;integer('book_id');
          $table-&gt;integer('status_id');
          $table-&gt;double('payment_amount')-&gt;nullable();
          $table-&gt;timestamp('received_at')-&gt;nullable();
          $table-&gt;timestamp('paid_at')-&gt;nullable();
          $table-&gt;timestamps();
          $table-&gt;softDeletes();
      });
  </code></pre>
  
  <p>And this is my <code>sell_shipping_labels</code> schema:</p>
  
  <pre><code>Schema::create('sell_shipping_labels', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;unsignedInteger('order_id');
          $table-&gt;string('shippo_object_id');
          $table-&gt;string('label_url');
          $table-&gt;string('tracking_url');
          $table-&gt;string('tracking_number');
          $table-&gt;timestamp('arrived_at');
          $table-&gt;timestamps();
          $table-&gt;softDeletes();
  
          $table-&gt;foreign('order_id')-&gt;references('id')-&gt;on('orders');
      });
  }
  </code></pre>
  
  <p>Now I've flipped the internet upside down trying to figure out the problem. All of the post about this problem all refer to the fact that the orders table must be created <strong>BEFORE</strong> the table that has the foreign key on it but this isn't a problem for me because my files are in the correct order.</p>