Пытаюсь реализовать связку таблиц, но следующая ошибка при попытки сделать миграцию.
Ошибка:
<i>Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `permission_role` add constraint `permission_role_permission_id_foreign` foreign key (`permission_id`) references `permissions` (`id`) on delete cascade)</i>
Таблица
`users`
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->unsignedInteger('role_id')->index();
$table->foreign('role_id')->references('id')->on('roles');
$table->rememberToken();
$table->timestamps();
});
Таблица
`roles`
Schema::create('roles', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('description')->nullable();
$table->timestamps();
});
Таблица
`permissions`
Schema::create('permissions', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name')->nullable();
$table->string('key')->nullable();
$table->string('controller');
$table->string('method');
$table->timestamps();
});
Schema::create('permission_role', function (Blueprint $table) {
$table->unsignedInteger('permission_id');
$table->unsignedInteger('role_id');
$table->foreign('permission_id')
->references('id')
->on('permissions')
->onDelete('cascade');
$table->foreign('role_id')
->references('id')
->on('roles')
->onDelete('cascade');
$table->primary(['permission_id', 'role_id']);
});
Иерархия...