错误号:laravel 5.5 中的 150 "Foreign key constraint is incorrectly formed"

errno: 150 "Foreign key constraint is incorrectly formed" in laravel 5.5

我有 users table 存储所有 学生 教师 的详细信息。

teachers 可以创建 students,这些引用存储在 users_references table.

用户table

Schema::create('users', function (Blueprint $table) 
{
     $table->increments('id')->unsigned();
     $table->string('name');
     $table->string('uniqueid')->unique();
     $table->integer('contactnumber');
     $table->string('password');
}

users_references table

    Schema::create('users_references', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('userid');
        $table->integer('teacherid');
        $table->enum('status',['A','I']);
        $table->timestamps();

        $table->foreign('userid')
              ->references('id')
              ->on('users')
              ->onDelete('cascade');

        $table->foreign('teacherid')
              ->references('id')
              ->on('users')
              ->onDelete('cascade');
    });

迁移时出现错误

尝试在 users_references table 中为 id 添加 unsigned()。 Laravel的increments('id')函数创建了一个无符号整数,所以外键列也需要是无符号的。