title: Laravel foreign key constraint is incorrectly formed I have searched and cannot find the answer
body: <pre class="lang-php prettyprint-override"><code>class CreateMediaTable extends Migration
  {
      public function up()
      {
          Schema::create('media', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;unsignedBigInteger('id_users');
              $table-&gt;unsignedBigInteger('id_posts');
              $table-&gt;char('type', 1); //P: photo or V: video
              $table-&gt;string('file');
              $table-&gt;timestamps();
  
              $table-&gt;foreign('id_posts')-&gt;references('id')-&gt;on('posts');
              $table-&gt;foreign('id_users')-&gt;references('id')-&gt;on('users');
          });
      }
  
      public function down()
      {
          Schema::dropIfExists('posts');
      }
  }
  </code></pre>
  
  <p>and my createprofilemigration </p>
  
  <pre><code>/**
   * @author Alex Madsen
   * 
   * @date November 6, 2018
   */ 
  
  use Illuminate\Support\Facades\Schema;
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Database\Migrations\Migration;
  
  class CreateUserProfilesTable extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::create('user_profiles', function (Blueprint $table) {
              $table-&gt;unsignedInteger('id_users')-&gt;unique();
              $table-&gt;string('handle')-&gt;unique(); 
              $table-&gt;string('icon')-&gt;default('https://i.redd.it/130am13nj6201.png'); 
              $table-&gt;string('profile_image')-&gt;nullable(); 
              $table-&gt;string('description')-&gt;nullable(); 
              $table-&gt;timestamps();
          });
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          Schema::dropIfExists('user_profiles');
      }
  }
  </code></pre>
  
  <p><strong>Keeps throwing these errors, What am I missing? Mind you I am new to this, Trying to learn with youtube and stackoverflow on my off time. Not sure which way to go. I have looked on the forums and tried              $table->foreign('id_posts')->references('id')->on('posts'); But it didn't fix the issue.</strong></p>
  
  <pre><code>Illuminate\Database\QueryException  : SQLSTATE[HY000]: General error: 1005 Can't create table `ci`.`media` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter t
  able `media` add constraint `media_id_posts_foreign` foreign key (`id_posts`) references `posts` (`id`))
  
    at C:\xampp6\htdocs\lol\simple_social_network_laravel\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
      660|         // If an exception occurs when attempting to run a query, we'll format the error
      661|         // message to include the bindings with SQL, which will make this exception a
      662|         // lot more helpful to the developer instead of just the database's errors.
      663|         catch (Exception $e) {
    &gt; 664|             throw new QueryException(
      665|                 $query, $this-&gt;prepareBindings($bindings), $e
      666|             );
      667|         } 
  </code></pre>
  
  <pre class="lang-php prettyprint-override"><code>class CreatePostsTable extends Migration
  {
      public function up()
      {
          Schema::create('posts', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;unsignedBigInteger('id_users');
              $table-&gt;unsignedInteger('subreddit_id');
              $table-&gt;text('description');
              $table-&gt;string('title');
              $table-&gt;text('content');
              $table-&gt;unsignedInteger('id_posts');
              $table-&gt;timestamps();
  
              $table-&gt;foreign('id_users')-&gt;references('id')-&gt;on('users');
              $table-&gt;foreign('subreddit_id')-&gt;references('id')-&gt;on('id_posts');
          });
      }
  
      public function down()
      {
          Schema::dropIfExists('posts');
      }
  }
  </code></pre>