title: Illuminate\Database\QueryException SQLSTATEHY000: General error: 1215
body: <p>I'm currently working on a school project and ran in to this problem with my database,
  I want to create a relationship with videos and categories here are my two tables.
  The video table:</p>
  
  <pre><code>&lt;?php
  
  use Illuminate\Support\Facades\Schema;
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Database\Migrations\Migration;
  
  class CreateVideosTable extends Migration
  {
  /**
   * Run the migrations.
   *
   * @return void
   */
  public function up()
  {
      Schema::create('videos', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;string('name')-&gt;default('');
          $table-&gt;string('url')-&gt;default('');
  
          $table-&gt;integer('category_id')-&gt;unsigned()-&gt;nullable();
          $table-&gt;foreign('category_id')-&gt;references('id')-&gt;on('categories');
  
          $table-&gt;string('img_url')-&gt;default('');
          $table-&gt;integer('views')-&gt;nullable();
          $table-&gt;integer('rating')-&gt;nullable();
          $table-&gt;timestamps();
      });
  }
  
  /**
   * Reverse the migrations.
   *
   * @return void
   */
  public function down()
  {
      Schema::dropIfExists('videos');
  }
  }
  </code></pre>
  
  <p>And the categories table:</p>
  
  <pre><code>&lt;?php
  
  use Illuminate\Support\Facades\Schema;
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Database\Migrations\Migration;
  
  class CreateCategoriesTable extends Migration
  {
  /**
   * Run the migrations.
   *
   * @return void
   */
  public function up()
  {
      Schema::create('categories', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;string('name');
          $table-&gt;timestamps();
      });
  }
  
  /**
   * Reverse the migrations.
   *
   * @return void
   */
  public function down()
  {
      Schema::dropIfExists('categories');
  }
  }
  </code></pre>
  
  <p>When i run php artisan migrate:refresh in the console i get this error:</p>
  
  <pre><code>[Illuminate\Database\QueryException] SQLSTATE[HY000]: General error: 1215 
  Cannot add foreign key constraint (SQL: alter table `videos` add constraint 
  `videos_category_id_foreign` foreign key (`category_id`) references 
  `categories` (`id`))
  </code></pre>
  
  <p>[PDOException]
    SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint</p>
  
  <p>i dont see why because when i change this:</p>
  
  <pre><code>$table-&gt;foreign('category_id')-&gt;references('id')-&gt;on('categories');
  </code></pre>
  
  <p>to this:</p>
  
  <pre><code>$table-&gt;foreign('category_id')-&gt;references('id')-&gt;on('users');
  </code></pre>
  
  <p>It works and then i have no error's whatsoever, i hope someone can help me out with this!</p>