title: How to add foreign key in laravel migration?
body: <p>I have an employer_profiles table, a job_posts table and an employer_profile_job_post table. I'm trying to make a relationship and add the foreign keys but I keep getting this error and I'm not sure why.</p>
  <pre><code>SQLSTATE[HY000]: General error: 1005 Can't create table `highrjobsadminlte`.`employer_profile_job_post` (errno: 150 &quot;Foreign key constraint is incorrectly formed&quot;) (SQL: alter table `employer_profile_job_post` add constraint `employer_profile_job_post_job_post_id_foreign` foreign key (`job_post_id`) references `job_posts` (`id`))
  </code></pre>
  <p>create_employer_profile_job_post_table.php:</p>
  <pre><code>public function up()
  {
      Schema::create('employer_profile_job_post', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;bigInteger('employer_profile_id')-&gt;unsigned()-&gt;index();
          $table-&gt;bigInteger('job_post_id')-&gt;unsigned()-&gt;index();
          $table-&gt;timestamps();
  
          $table-&gt;foreign('employer_profile_id')-&gt;references('id')-&gt;on('employer_profiles');
          $table-&gt;foreign('job_post_id')-&gt;references('id')-&gt;on('job_posts');
      });
  }
  </code></pre>
  <p>create_employer_profiles_table.php:</p>
  <pre><code>public function up()
  {
      Schema::create('employer_profiles', function (Blueprint $table) {
          $table-&gt;id();
          $table-&gt;bigInteger('user_id')-&gt;index()-&gt;unsigned();
          $table-&gt;string('company_name');
          $table-&gt;string('phone',30)-&gt;nullable();
          $table-&gt;string('street');
          $table-&gt;string('city', 50);
          $table-&gt;string('country', 80);
          $table-&gt;string('zip_postal', 25);
          $table-&gt;string('province_state', 50);
          $table-&gt;string('number_of_employees');
          $table-&gt;timestamps();
  
          $table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users');
      });
  }
  </code></pre>
  <p>create_job_posts_table.php:</p>
  <pre><code>public function up()
      {
          Schema::create('job_posts', function (Blueprint $table) {
              $table-&gt;id();
              $table-&gt;bigInteger('user_id')-&gt;index()-&gt;unsigned();
              $table-&gt;bigInteger('employer_profile_id')-&gt;index()-&gt;unsigned();
              $table-&gt;string('job_title');
              $table-&gt;longText('job_description');
              $table-&gt;string('salary', 20);
              $table-&gt;string('employment_type', 20)-&gt;nullable();
              $table-&gt;string('location_name', 100);
              $table-&gt;tinyInteger('is_active')-&gt;default(0);
              $table-&gt;timestamps();
  
              $table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users');
              $table-&gt;foreign('employer_profile_id')-&gt;references('id')-&gt;on('employer_profiles');
          });
      }
  </code></pre>