迁移:无法添加外键约束
我试图在Laravel中创建外键,但是当我使用我的表进行迁移artisan时,抛出以下错误: [Illuminate\Database\QueryException] SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL : alter table `priorities` add constraint priorities_user_id_foreign foreign key (`user_id`) references `users` (`id`)) 我的迁移代码是这样的: 优先级迁移文件 public function up() { // Schema::create('priorities', function($table) { $table->increments('id', true); $table->integer('user_id'); $table->foreign('user_id')->references('id')->on('users'); $table->string('priority_name'); $table->smallInteger('rank'); $table->text('class'); $table->timestamps('timecreated'); }); } /** * Reverse the migrations. …