title: General error: 1824 Failed to open the referenced table
body: <p>I am trying to set foreign key of my 'books' table with 'categories' table using php artisan migrate, but I got the following error:</p>
  
  <pre><code>    Illuminate\Database\QueryException 
  
    SQLSTATE[HY000]: General error: 1824 Failed to open the referenced table 'categories' (SQL: alter table `books` add constraint `books_category_id_foreign` foreign key (`category_id`) references `categories` (`id`))
  </code></pre>
  
  <p>books migration file: </p>
  
  <pre><code>public function up()
  {
      Schema::create('books', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;integer('category_id')-&gt;unsigned();
          $table-&gt;foreign('category_id')-&gt;references('id')-&gt;on('categories');
          $table-&gt;string("image");
          $table-&gt;string("title");
          $table-&gt;string("description")-&gt;nullable();
          $table-&gt;string("author");
          $table-&gt;string("cover");
          $table-&gt;integer("nod")-&gt;nullable();// Number of downloads
          $table-&gt;integer("rating")-&gt;nullable();
          $table-&gt;timestamps();
      });
  }
  
  /**
   * Reverse the migrations.
   *
   * @return void
   */
  public function down()
  {
      Schema::dropIfExists('books');
  }
  </code></pre>
  
  <p>categories migration file: </p>
  
  <pre><code>public function up()
  {
      Schema::create('categories', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;string("title");
          $table-&gt;string("image");
          $table-&gt;timestamps();
      });
  }
  
  /**
   * Reverse the migrations.
   *
   * @return void
   */
  public function down()
  {
      Schema::dropIfExists('categories');
  }
  </code></pre>
  
  <p>I really need help with this to use in my mobile app API. I hope someone can help me.</p>