Laravel-permission: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'model_id' in 'field list'

Created on 26 May 2018  路  3Comments  路  Source: spatie/laravel-permission

hello I'm trying to use Spatie but, I can add permissions, but I can not assign a role to a user nor can I get getRoleNames (), when I assign a role, it returns this:
{ "message": "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'model_id' in 'field list' (SQL: updaterolessetupdated_at= 2018-05-25 22:43:49,model_id= 20 whereid= 1)", "exception": "Illuminate\\Database\\QueryException", "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Database/Connection.php", "line": 664, "trace": [ { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Database/Connection.php", "line": 624, "function": "runQueryCallback", "class": "Illuminate\\Database\\Connection", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Database/Connection.php", "line": 490, "function": "run", "class": "Illuminate\\Database\\Connection", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Database/Connection.php", "line": 423, "function": "affectingStatement", "class": "Illuminate\\Database\\Connection", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php", "line": 2173, "function": "update", "class": "Illuminate\\Database\\Connection", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php", "line": 782, "function": "update", "class": "Illuminate\\Database\\Query\\Builder", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php", "line": 628, "function": "update", "class": "Illuminate\\Database\\Eloquent\\Builder", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php", "line": 543, "function": "performUpdate", "class": "Illuminate\\Database\\Eloquent\\Model", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php", "line": 250, "function": "save", "class": "Illuminate\\Database\\Eloquent\\Model", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php", "line": 262, "function": "save", "class": "Illuminate\\Database\\Eloquent\\Relations\\HasOneOrMany", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/spatie/laravel-permission/src/Traits/HasRoles.php", "line": 93, "function": "saveMany", "class": "Illuminate\\Database\\Eloquent\\Relations\\HasOneOrMany", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/app/Http/Controllers/UserController.php", "line": 119, "function": "assignRole", "class": "App\\User", "type": "->" }, { "function": "update", "class": "App\\Http\\Controllers\\UserController", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Controller.php", "line": 54, "function": "call_user_func_array" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php", "line": 45, "function": "callAction", "class": "Illuminate\\Routing\\Controller", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Route.php", "line": 212, "function": "dispatch", "class": "Illuminate\\Routing\\ControllerDispatcher", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Route.php", "line": 169, "function": "runController", "class": "Illuminate\\Routing\\Route", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 658, "function": "run", "class": "Illuminate\\Routing\\Route", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 30, "function": "Illuminate\\Routing\\{closure}", "class": "Illuminate\\Routing\\Router", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php", "line": 41, "function": "Illuminate\\Routing\\{closure}", "class": "Illuminate\\Routing\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 149, "function": "handle", "class": "Illuminate\\Routing\\Middleware\\SubstituteBindings", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\\Pipeline\\{closure}", "class": "Illuminate\\Pipeline\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php", "line": 67, "function": "Illuminate\\Routing\\{closure}", "class": "Illuminate\\Routing\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 149, "function": "handle", "class": "Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\\Pipeline\\{closure}", "class": "Illuminate\\Pipeline\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php", "line": 49, "function": "Illuminate\\Routing\\{closure}", "class": "Illuminate\\Routing\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 149, "function": "handle", "class": "Illuminate\\View\\Middleware\\ShareErrorsFromSession", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\\Pipeline\\{closure}", "class": "Illuminate\\Pipeline\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php", "line": 63, "function": "Illuminate\\Routing\\{closure}", "class": "Illuminate\\Routing\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 149, "function": "handle", "class": "Illuminate\\Session\\Middleware\\StartSession", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\\Pipeline\\{closure}", "class": "Illuminate\\Pipeline\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php", "line": 37, "function": "Illuminate\\Routing\\{closure}", "class": "Illuminate\\Routing\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 149, "function": "handle", "class": "Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\\Pipeline\\{closure}", "class": "Illuminate\\Pipeline\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php", "line": 59, "function": "Illuminate\\Routing\\{closure}", "class": "Illuminate\\Routing\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 149, "function": "handle", "class": "Illuminate\\Cookie\\Middleware\\EncryptCookies", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\\Pipeline\\{closure}", "class": "Illuminate\\Pipeline\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 102, "function": "Illuminate\\Routing\\{closure}", "class": "Illuminate\\Routing\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 660, "function": "then", "class": "Illuminate\\Pipeline\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 635, "function": "runRouteWithinStack", "class": "Illuminate\\Routing\\Router", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 601, "function": "runRoute", "class": "Illuminate\\Routing\\Router", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 590, "function": "dispatchToRoute", "class": "Illuminate\\Routing\\Router", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php", "line": 176, "function": "dispatch", "class": "Illuminate\\Routing\\Router", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 30, "function": "Illuminate\\Foundation\\Http\\{closure}", "class": "Illuminate\\Foundation\\Http\\Kernel", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/fideloper/proxy/src/TrustProxies.php", "line": 56, "function": "Illuminate\\Routing\\{closure}", "class": "Illuminate\\Routing\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 149, "function": "handle", "class": "Fideloper\\Proxy\\TrustProxies", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\\Pipeline\\{closure}", "class": "Illuminate\\Pipeline\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php", "line": 30, "function": "Illuminate\\Routing\\{closure}", "class": "Illuminate\\Routing\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 149, "function": "handle", "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\\Pipeline\\{closure}", "class": "Illuminate\\Pipeline\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php", "line": 30, "function": "Illuminate\\Routing\\{closure}", "class": "Illuminate\\Routing\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 149, "function": "handle", "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\\Pipeline\\{closure}", "class": "Illuminate\\Pipeline\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php", "line": 27, "function": "Illuminate\\Routing\\{closure}", "class": "Illuminate\\Routing\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 149, "function": "handle", "class": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\\Pipeline\\{closure}", "class": "Illuminate\\Pipeline\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php", "line": 46, "function": "Illuminate\\Routing\\{closure}", "class": "Illuminate\\Routing\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 149, "function": "handle", "class": "Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\\Pipeline\\{closure}", "class": "Illuminate\\Pipeline\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/itsgoingd/clockwork/Clockwork/Support/Laravel/ClockworkMiddleware.php", "line": 28, "function": "Illuminate\\Routing\\{closure}", "class": "Illuminate\\Routing\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 149, "function": "handle", "class": "Clockwork\\Support\\Laravel\\ClockworkMiddleware", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\\Pipeline\\{closure}", "class": "Illuminate\\Pipeline\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 102, "function": "Illuminate\\Routing\\{closure}", "class": "Illuminate\\Routing\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php", "line": 151, "function": "then", "class": "Illuminate\\Pipeline\\Pipeline", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php", "line": 116, "function": "sendRequestThroughRouter", "class": "Illuminate\\Foundation\\Http\\Kernel", "type": "->" }, { "file": "/home/vagrant/code/StudioContable/public/index.php", "line": 55, "function": "handle", "class": "Illuminate\\Foundation\\Http\\Kernel", "type": "->" } ] }

support

Most helpful comment

"message": "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'model_id' in 'field list' (SQL: updaterolessetupdated_at= 2018-05-25 22:43:49,model_id= 20 whereid= 1)"

The error message is telling you that the model_id field doesn't exist in the roles table.

This can be caused by 3 scenarios:

  1. You previously had a roles table, so you skipped running the supplied migration as provided, and didn't update the migration to apply the necessary schema changes to support what this package requires.

  2. Or you previously used v1 of this package and had tables from it, but then you upgraded to v2, which is not compatible with the v1 data.
    If you are upgrading from v1 to v2 you need to manually convert your data to the new format. There is no "upgrade" script provided for the change from v1 to v2.

  3. Another possibility is that you might have mistakenly run incomplete migrations on your localhost and not yet full migrations on the vagrant machine.

All 3 comments

"message": "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'model_id' in 'field list' (SQL: updaterolessetupdated_at= 2018-05-25 22:43:49,model_id= 20 whereid= 1)"

The error message is telling you that the model_id field doesn't exist in the roles table.

This can be caused by 3 scenarios:

  1. You previously had a roles table, so you skipped running the supplied migration as provided, and didn't update the migration to apply the necessary schema changes to support what this package requires.

  2. Or you previously used v1 of this package and had tables from it, but then you upgraded to v2, which is not compatible with the v1 data.
    If you are upgrading from v1 to v2 you need to manually convert your data to the new format. There is no "upgrade" script provided for the change from v1 to v2.

  3. Another possibility is that you might have mistakenly run incomplete migrations on your localhost and not yet full migrations on the vagrant machine.

This answer is quite late but will be helpful o whoever will find it. Use 'php artisan migrate rollback' to un do the tabe you created and then run php artisan migrate again. I'm adding on what drbryte stated

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'pivot.post_id' in 'where clause' (SQL: select count(*) as aggregate from posts inner join post_user on posts.id = post_user.post_id where post_user.user_id = 1 and pivot.post_id = 45) (View: C:\xampp\htdocs\blog\resources\views\welcome.blade.php)

brother what's the problem please help me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

ionesculiviucristian picture ionesculiviucristian  路  4Comments

MichalKrakow picture MichalKrakow  路  4Comments

hosseinnedaei picture hosseinnedaei  路  3Comments

neoreids picture neoreids  路  3Comments