laravel-permission: [5.9.0] Artisan migrate throwing QueryException

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.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 23 (4 by maintainers)

Most upvoted comments

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.

v5.9.1 reverted the change.

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.

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.

@erikn69 you’re correct. The problem started after the last push to spatie:main 2 hours ago

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”

I confirm the same error here. Can’t run the package migration for 5.9.0.