spatie/laravel-permission

[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:

  1. Create fresh Laravel App
  2. composer require spatie/laravel-permission
  3. Add HasRoles to User
  4. 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?

@erikn69 At the moment I am not 100% sure about #2309 , but it looks like PermissionRegistrar class is not instantiated. I just looked at the migration file and PermissionRegistrar.php file for v5.9.0 in my machine.

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

gmlo89 commented

Same error here!
SQLSTATE[42000]: Syntax error or access violation: 1166 Incorrect column name '' (SQL: create tablemodel_has_permissions ...

I have the same problem too..

Laravel: 9.50.2
Permission package: 5.9.0
PHP: 8.2.2
image

The current alternative that can be done is downgrade to version 5.8.

Hopefully this issue is quickly resolved.. :)

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!
image

I did a manual change in the vendor according to this reference "erikn69@09088c0" and tested it in a new project.

image

image

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 and 5.8

@AhmedMub perhaps @erikn69 solution might work for you.

drbyte commented

v5.9.1 reverted the change.