简体   繁体   English

Laravel Spatie 权限 - 未找到基表或视图:1146 表“my_database.models”不存在

[英]Laravel Spatie Permissions - Base table or view not found: 1146 Table 'my_database.models' doesn't exist

I'm getting an error when using spatie permissions and trying to assign a role using:使用 spatie 权限并尝试使用以下方式分配角色时出现错误:

$user->assignRole('admin');

The error is the following:错误如下:

Base table or view not found: 1146 Table 'my_database.models' doesn't exist (SQL: select * from `models` where `user_id` = 38 and `model_type` = App\User) 

Where is the value "models" being set?, that table doesn't exist but, where do I set the value?, I can't seem to find it, I have already checked inside config/permission.php .值“模型”在哪里设置?,该表不存在,但是,我在哪里设置值?,我似乎找不到它,我已经在config/permission.php里面检查了。

My permission file is the following:我的permission文件如下:

return [

'models' => [

    /*
     * When using the "HasPermissions" trait from this package, we need to know which
     * Eloquent model should be used to retrieve your permissions. Of course, it
     * is often just the "Permission" model but you may use whatever you like.
     *
     * The model you want to use as a Permission model needs to implement the
     * `Spatie\Permission\Contracts\Permission` contract.
     */

    'permission' => Spatie\Permission\Models\Permission::class,

    /*
     * When using the "HasRoles" trait from this package, we need to know which
     * Eloquent model should be used to retrieve your roles. Of course, it
     * is often just the "Role" model but you may use whatever you like.
     *
     * The model you want to use as a Role model needs to implement the
     * `Spatie\Permission\Contracts\Role` contract.
     */

    'role' => Spatie\Permission\Models\Role::class,

],

'table_names' => [

    /*
     * When using the "HasRoles" trait from this package, we need to know which
     * table should be used to retrieve your roles. We have chosen a basic
     * default value but you may easily change it to any table you like.
     */

    'roles' => 'roles',

    /*
     * When using the "HasPermissions" trait from this package, we need to know which
     * table should be used to retrieve your permissions. We have chosen a basic
     * default value but you may easily change it to any table you like.
     */

    'permissions' => 'permissions',

    /*
     * When using the "HasPermissions" trait from this package, we need to know which
     * table should be used to retrieve your models permissions. We have chosen a
     * basic default value but you may easily change it to any table you like.
     */

    'users_has_permissions' => 'users_has_permissions',

    /*
     * When using the "HasRoles" trait from this package, we need to know which
     * table should be used to retrieve your models roles. We have chosen a
     * basic default value but you may easily change it to any table you like.
     */

    'users_has_roles' => 'users_has_roles',

    /*
     * When using the "HasRoles" trait from this package, we need to know which
     * table should be used to retrieve your roles permissions. We have chosen a
     * basic default value but you may easily change it to any table you like.
     */

    'role_has_permissions' => 'role_has_permissions',
],

'column_names' => [

    /*
     * Change this if you want to name the related model primary key other than
     * `model_id`.
     *
     * For example, this would be nice if your primary keys are all UUIDs. In
     * that case, name this `model_uuid`.
     */

    'model_morph_key' => 'user_id',
],

/*
 * When set to true, the required permission/role names are added to the exception
 * message. This could be considered an information leak in some contexts, so
 * the default setting is false here for optimum safety.
 */

'display_permission_in_exception' => false,

/*
 * By default wildcard permission lookups are disabled.
 */

'enable_wildcard_permission' => false,

'cache' => [

    /*
     * By default all permissions are cached for 24 hours to speed up performance.
     * When permissions or roles are updated the cache is flushed automatically.
     */

    'expiration_time' => \DateInterval::createFromDateString('24 hours'),

    /*
     * The cache key used to store all permissions.
     */

    'key' => 'spatie.permission.cache',

    /*
     * When checking for a permission against a model by passing a Permission
     * instance to the check, this key determines what attribute on the
     * Permissions model is used to cache against.
     *
     * Ideally, this should match your preferred way of checking permissions, eg:
     * `$user->can('view-posts')` would be 'name'.
     */

    'model_key' => 'name',

    /*
     * You may optionally indicate a specific cache driver to use for permission and
     * role caching using any of the `store` drivers listed in the cache.php config
     * file. Using 'default' here means to use the `default` set in cache.php.
     */

    'store' => 'default',
],
];

As you can see, my pivot tables have been set to: users_has_permissions and users_has_roles如您所见,我的 pivot 表已设置为: users_has_permissionsusers_has_roles

I have solved the problem, apparently you can't change the key name in the config/permission.php file, so I had:我已经解决了这个问题,显然你不能更改config/permission.php文件中的键名,所以我有:

/*
         * When using the "HasPermissions" trait from this package, we need to know which
         * table should be used to retrieve your models permissions. We have chosen a
         * basic default value but you may easily change it to any table you like.
         */

        'user_has_permissions' => 'user_has_permissions',

        /*
         * When using the "HasRoles" trait from this package, we need to know which
         * table should be used to retrieve your models roles. We have chosen a
         * basic default value but you may easily change it to any table you like.
         */

        'user_has_roles' => 'user_has_roles',

I just set the key from the array to what it was at the beginning:我只是将数组中的键设置为开始时的键:

/*
         * When using the "HasPermissions" trait from this package, we need to know which
         * table should be used to retrieve your models permissions. We have chosen a
         * basic default value but you may easily change it to any table you like.
         */

    'model_has_permissions' => 'user_has_permissions',

    /*
     * When using the "HasRoles" trait from this package, we need to know which
     * table should be used to retrieve your models roles. We have chosen a
     * basic default value but you may easily change it to any table you like.
     */

    'model_has_roles' => 'user_has_roles',

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel:未找到基表或视图:1146表'database.pages不存在 - Laravel: Base table or view not found: 1146 Table 'database.pages doesn't exist Laravel 8 - 未找到基表或视图:1146 表“laravel8.brand”不存在 - Laravel 8 - Base table or view not found: 1146 Table 'laravel8.brand' doesn't exist LARAVEL - 未找到基表或视图:1146 表不存在(SQL: select * from ) - LARAVEL - Base table or view not found: 1146 Table doesn't exist (SQL: select * from ) SQLSTATE[42S02]:未找到基表或视图:1146 表“My_database_Name.posts”不存在 - SQLSTATE[42S02]: Base table or view not found: 1146 Table 'My_database_Name.posts' doesn't exist 未找到基表或视图:1146 表 'ifs.employees' 不存在 Laravel 错误 - Base table or view not found: 1146 Table 'ifs.employees' doesn't exist Laravel Error SQLSTATE[42S02]:未找到基表或视图:1146 表 '***.indices' 不存在 laravel - SQLSTATE[42S02]: Base table or view not found: 1146 Table '***.indices' doesn't exist laravel SQLSTATE [42S02]:找不到基表或视图:1146表'prj_roocket.permissions'不存在 - SQLSTATE[42S02]: Base table or view not found: 1146 Table 'prj_roocket.permissions' doesn't exist Laravel - PDOException::("SQLSTATE[42S02]: 未找到基表或视图:1146 表 'vestibulare.app\models\telefone' 不存在 - Laravel - PDOException::("SQLSTATE[42S02]: Base table or view not found: 1146 Table 'vestibulare.app\models\telefone' doesn't exist SQLSTATE [42S02]:未找到基表或视图:1146 表“laravel_abonamenty2.currencies”不存在 - SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel_abonamenty2.currencies' doesn't exist SQLSTATE[42S02]: 未找到基表或视图:1146 表 'laravel9rentalcars.categories' 不存在 - SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel9rentalcars.categories' doesn't exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM