本文介绍了SQLSTATE [42S02]:找不到基表或视图:1146表'prj_roocket.permissions'不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建迁移

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...编写的任何内容都会出现此错误.我也删除了数据库,然后创建了一个新数据库.

Any what I write in CMD php artisan migrate and composer dumpautoload and php artisan serve and... This error is seen. and too I deleted database and I create a new database.

[PDOException] SQLSTATE [42S02]:找不到基表或视图:1146 表'prj_roocket.permissions'不存在

[PDOException] SQLSTATE[42S02]: Base table or view not found: 1146 Table 'prj_roocket.permissions' doesn't exist

推荐答案

此错误是由 AuthServiceProvider 中的函数 getPermissions 给出的(或者您定义了身份验证服务的其他地方)提供者).

This error is given by the function getPermissions in AuthServiceProvider (or somewhere else you defined your authentication service provider).

可能您的函数如下所示:

Probabily your function looks like this:

protected function getPermissions()
{
    return Permission::with('roles')->get();
}

尝试将功能 getPermissions 替换为:

protected function getPermissions()
{
    try {
        return Permission::with('roles')->get();
    } catch (\Exception $e) {
        return [];
    }
}

,然后再次运行 php artisan migration .

注意:有了此修复程序,您将不会损害系统安全性.

Note: with this fix you are not going to compromise the system security.

这篇关于SQLSTATE [42S02]:找不到基表或视图:1146表'prj_roocket.permissions'不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 06:26