SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint Laravel : <p>Im trying to create a foreign keys using <code>artisan</code>, but this error show up.</p>

<pre><code>[Illuminate\Database\QueryException]                                                                                                                                                                             
  SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `comments` add constraint `comments_comment_lot_id_foreign` foreign key (`comment_lot_id`) references `lots` (`lot_id`  
  ) on delete cascade) 
</code></pre>

<p>This is my migration: </p>

<pre><code>&lt;?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCommentsTable extends Migration
{

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('comments', function (Blueprint $table) {
            $table-&gt;increments('id');
            $table-&gt;text('comment');
            $table-&gt;integer('comment_lot_id')-&gt;unsigned();
            $table-&gt;timestamps();
        });

        Schema::table('comments', function ($table) {
            $table-&gt;foreign('comment_lot_id')-&gt;references('lot_id')-&gt;on('lots')-&gt;onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropForeign(['comment_lot_id']);
        Schema::dropIfExists('comments');
    }
}
</code></pre>

<p>in the lots table i use <code>lot_id</code> as <code>id</code>  it model Lot.php i add:</p>

<pre><code>&lt;?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Lot extends Model {
    protected $primaryKey = 'lot_id';

}
</code></pre>

<p>Any idea how can i resolve this error? </p>
