title: Laravel migration Error no: 150 "Foreign key constraint is incorrectly formed"
body: <p>I have a ‘posts’ table and an ‘arrival’ table which references ‘flightno’ <em>(in text string format)</em> as a foreign key. However, when I run the Laravel migration I get the dreaded error:</p>
  
  <blockquote>
    <p>[Illuminate\Database\QueryException]
    SQLSTATE[HY000]: General error: 1005 Can't create table <code>atc</code>.<code>#sql-2350_84</code> (errno: 150 "Foreign key constraint is
    incorrectly formed") (SQL: alter table <code>arrival</code> add constraint
    <code>arrival_flightno_foreign</code> foreign key (<code>flightno</code>) references <code>posts</code>
    (<code>flightno</code>))</p>
    
    <p>[PDOException]
    SQLSTATE[HY000]: General error: 1005 Can't create table <code>atc</code>.<code>#sql-2350_84</code> (errno: 150 "Foreign key constraint is
    incorrectly formed")</p>
  </blockquote>
  
  <p><strong>Posts</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>Schema::create('posts', function (Blueprint $table) {
      $table-&gt;increments('id');
      $table-&gt;string('flightno');
      $table-&gt;string('flighttype');
      $table-&gt;string('toa');
      $table-&gt;string('doa');
      $table-&gt;string('runway');
      $table-&gt;string('route');
      $table-&gt;string('parking');
      $table-&gt;timestamps();
  }); 
  </code></pre>
  
  <p><strong>Arrival</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>Schema::create('arrival', function (Blueprint $table) {
      $table-&gt;increments('id');
      $table-&gt;string('flightno');
      $table-&gt;string('cleaning');
      $table-&gt;string('rampservice');
      $table-&gt;string('waste');
      $table-&gt;string('deicing');
      $table-&gt;foreign('flightno')-&gt;references('flightno')-&gt;on('posts')-&gt;onDelete('cascade');
      $table-&gt;timestamps();
  });
  </code></pre>