我创建了一个迁移
Schema::create('roles', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('label')->nullable();
$table->timestamps();
});
Schema::create('permissions', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('label')->nullable();
$table->timestamps();
});
Schema::create('permission_role', function (Blueprint $table) {
$table->integer('role_id')->unsigned();
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
$table->integer('permission_id')->unsigned();
$table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');
$table->primary(['role_id' , 'permission_id']);
});
Schema::create('role_user', function (Blueprint $table) {
$table->integer('role_id')->unsigned();
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->primary(['role_id' , 'user_id']);
});
我在CMD php artisan migrate and composer dumpautoload and php artisan serve and...
写的任何内容都可以看到这个错误。我也删除了数据库,并创建了一个新的数据库。
[Illuminate \ Database \ QueryException] SQLSTATE [42S02]:未找到基表或视图:1146表'prj_roocket.permissions'不存在(SQL:select * from
permissions
)[PDOException] SQLSTATE [42S02]:找不到基表或视图:1146表'prj_roocket.permissions'不存在
此错误由AuthServiceProvider中的函数getPermissions(或您定义的身份验证服务提供程序的其他位置)给出。
可能你的功能看起来像这样:
protected function getPermissions()
{
return Permission::with('roles')->get();
}
尝试将函数getPermissions替换为:
protected function getPermissions()
{
try {
return Permission::with('roles')->get();
} catch (\Exception $e) {
return [];
}
}
然后再次运行php artisan migrate。
注意:使用此修复程序,您不会破坏系统安全性。