我已经添加了我所有的 in 约束2020_06_17_221942_create_constraints_table 但它不起作用 所有迁移均已成功完成,但没有任何表约束,2020_06_17_221942_create_constraints_table为:
Schema::table('seasons', function (Blueprint $table) {
$table->unsignedBigInteger('best_project_id');
$table->unsignedBigInteger('manager_id');
$table->foreign('best_project_id')->references('id')->on('projects');
$table->foreign('manager_id')->references('id')->on('users');
});
Schema::table('admins', function (Blueprint $table) {
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onDelete('cascade');;
});
Schema::table('projects', function (Blueprint $table) {
$table->foreign('study_major_id')->references('id')->on('study_majors');
$table->foreign('user_id')->references('id')->on('Users');
$table->foreign('season_id')->references('id')->on('Seasons');
})
尝试向迁移函数添加"蓝图"类型提示。它应该工作
例如:
Schema::table('seasons', function (Blueprint $table) {
$table->unsignedBigInteger('best_project_id');
$table->unsignedBigInteger('manager_id');
$table->foreign('best_project_id')->references('id')->on('projects');
$table->foreign('manager_id')->references('id')->on('users');
});
将最后一个查询替换为
Schema::table('projects', function (Blueprint $table) {
$table->unsignedBigInteger('study_major_id');
$table->unsignedBigInteger('user_id');
$table->unsignedBigInteger('season_id');
$table->foreign('study_major_id')->references('id')->on('study_majors');
$table->foreign('user_id')->references('id')->on('Users');
$table->foreign('season_id')->references('id')->on('Seasons');
});