Проблемы с миграцией Laravel - PullRequest
0 голосов
/ 18 июня 2020

Я добавил все свои ограничения 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');
    })

Ответы [ 2 ]

0 голосов
/ 18 июня 2020

Замените последний запрос на этот

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');
});
0 голосов
/ 18 июня 2020

Попробуйте добавить подсказку типа "Blueprint" к функции миграции. Должно работать

Например:

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');
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...