[5.9.0] Artisan migrate throwing QueryException
jure-knezovic opened this issue ยท 23 comments
After latest update to 5.9.0, php artisan migrate / migrate:fresh is throwing Query Exception.
SQLSTATE[42000]: Syntax error or access violation: 1166 Incorrect column name '' (SQL: create table model_has_permissions
(`` bigint unsigned not null, model_type
varchar(255) not null, `model_id` bigint unsigned not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')
Laravel: 9.50.2
Permission package: 5.9.0
PHP: 8.1
DB: mariadb 10.5
Steps to reproduce the behavior:
- Create fresh Laravel App
- composer require spatie/laravel-permission
- Add HasRoles to User
- php artisan migrate -> Query Exception
When permissions package is locked to 5.8.0, no QueryException is thrown.
I can also confirm I am getting the same error. I discovered this when one of my deploy jobs failed doing the migration stage.
Also trying to use this package in one of my new projects and facing the same error. For some reason the constructor in PermissionRegistrar class is not firing.
Pull request fix: Lazily bind dependencies seems to have started the issue.
One thing that comes to mind is the possibility of requiring a cache reset/refresh.
Same here. Clearing cache and performing a fresh migration does not solve the issue. For now, pin the version to 5.8.0
and it will work fine again.
I confirm the same error here. Can't run the package migration for 5.9.0.
I can confirm the same error for Laravel 9 and 8 fresh installation, after clearing the config cache and fresh migration does not solve the problem
Maybe related
#2319 (comment)
Same issue noticed. There is nothing to clear in cache for permissions.
In migration file, the "PermissionRegistrar" class is not instantiated and hence its constructor is not being called & no value set for its static variable $pivotPermission. Hence the migration query showing a blank column name while creating table "model_has_permissions"
@ashvin-php so, is #2309 the problem?
Confirming the problem.
Now updated dependencies on one of the projects on Laravel 9, and the tests failed with an exception in the migration.
In migration 2023_02_06_235146_create_permission_tables.php:78
\Spatie\Permission\PermissionRegistrar::$pivotRole
returns empty value, which causes error in creating table "model_has_permissions":
... syntax error (SQL: create table "model_has_permissions" ("" integer not null, ...
@ashvin-php try without that change, change it on vendor if it necessary, and give us a feedback
Same error here!
SQLSTATE[42000]: Syntax error or access violation: 1166 Incorrect column name '' (SQL: create table
model_has_permissions ...
Hey All. I appreciate all those who tested the reset/refresh cache option and I can personally also confirm it does not work. As @ahoiroman specified, lock your version to 5.8.0
until this is resolved. In my case I did the following in my composer.json file
"spatie/laravel-permission": "<5.7",
@erikn69 you're correct. The problem started after the last push to spatie:main
2 hours ago
Hey All. I appreciate all those who tested the reset/refresh cache option and I can personally also confirm it does not work. As @ahoiroman specified, lock your version to
5.8.0
until this is resolved. In my case I did the following in my composer.json file
"spatie/laravel-permission": "<5.7",
@mrtorks Unfortunately did not work for me, still have the same issue for 5.7
and 5.8
Hi, can somebody test this commit on 5.9.0 erikn69@09088c0, maybe that fix it
@erikn69 it works!
I did a manual change in the vendor according to this reference "erikn69@09088c0" and tested it in a new project.
I can confirm alongside @alfinauzikri That @erikn69 's solution works. I tested it on a fresh project using 5.9.0
. Great Job all around. @erikn69 I think a PR is warranted.
Hey All. I appreciate all those who tested the reset/refresh cache option and I can personally also confirm it does not work. As @ahoiroman specified, lock your version to
5.8.0
until this is resolved. In my case I did the following in my composer.json file
"spatie/laravel-permission": "<5.7",
@mrtorks Unfortunately did not work for me, still have the same issue for
5.7
and5.8
v5.9.1 reverted the change.