laravel SQLSTATE[42S02]:未找到基表或视图:1146 表“prj_roocket.permissions”不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47158676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:55:11  来源:igfitidea点击:

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

phplaravel

提问by Dan

I create a migration

我创建一个迁移

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']);
    });

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.

我在 CMD 中写的任何内容php artisan migrate and composer dumpautoload and php artisan serve and...都可以看到此错误。我也删除了数据库并创建了一个新数据库。

[Illuminate\Database\QueryException] SQLSTATE[42S02]: Base table or view not found: 1146 Table 'prj_roocket.permissions' doesn't exist (SQL: select * from permissions)

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

[Illuminate\Database\QueryException] SQLSTATE[42S02]:未找到基表或视图:1146 表“prj_roocket.permissions”不存在(SQL:select * from permissions

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

回答by Dan

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

此错误是由函数给出getPermissionsAuthServiceProvider(或其他地方你确定你的身份验证服务提供商)。

Probabily your function looks like this:

可能你的函数是这样的:

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

Try to replace the function getPermissionswith:

尝试将函数getPermissions替换为:

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

and then run php artisan migrateagain.

然后再次运行php artisan migrate

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

注意:使用此修复程序不会损害系统安全性。