Laravel-Backpack / PermissionManager

Admin interface for managing users, roles, permissions, using Backpack CRUD
http://backpackforlaravel.com
Other
516 stars 166 forks source link

php artisan migrate, says nothing to migrate #322

Closed mcfaith9 closed 1 year ago

mcfaith9 commented 1 year ago

Bug report

What I did: I followed the steps.

What happened:

Its says nothing to migrate, I dont know why the migration dosent work on the steps i followed.

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'project_teamwork_db.roles' doesn't exist (SQL: select roles.*, model_has_roles.model_id as pivot_model_id, model_has_roles.role_id as pivot_role_id, model_has_roles.model_type as pivot_model_type from roles inner join model_has_roles on roles.id = model_has_roles.role_id where model_has_roles.model_id in (1, 2) and model_has_roles.model_type = App\Models\User)

What I've already tried to fix it:

I just re create db and fresh migrate.

Backpack, Laravel, PHP, DB version:

"php": "^7.3|^8.0", "backpack/crud": "^5.5", "backpack/permissionmanager": "^6.0",

welcome[bot] commented 1 year ago

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication mediums:

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

-- Justin Case The Backpack Robot

jcastroa87 commented 1 year ago

Hi @mcfaith9,

Regarding your issue with Backpack, it is possible that the problem is related to your .env file. I recommend double-checking to ensure that your database credentials are correct. If your credentials are correct, you can try running php artisan config:clear to clear any cached configuration files.

If you continue to have issues, please provide us with more information on how you installed Backpack. This information can help us better understand the issue and provide a more accurate solution.

It would be helpful if you could provide a step-by-step explanation of how you installed Backpack. This would include any commands that you ran, any errors that you received, and any other relevant information.

We look forward to hearing back from you and helping to resolve this issue.

tabacitu commented 1 year ago

@mcfaith9 sounds to me like you missed a step in the installation procedure. I'm pretty sure you haven't run php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="migrations". And yes... if the migration isn't there... it can't be run... so the interface won't work.

Please go through the installation steps one more time, make sure to run everything.

If that doesn't solve it for you, dig a little deeper to debug:

(1) Your error says Table 'project_teamwork_db.roles' doesn't exist... well ok... why? Does the table actually exist in the db - take a look? I assume it does not.

(2) Is the migration published? Take a look at database/migrations - is the roles migration file there? If not... it means you haven't published it... so you gotta run the command again.

Let us know more info, if this doesn't solve it. Cheers!

rkvandervaart commented 1 year ago

Hello,

I had the same issue as mcfaith9. Im on my first laravel project from scratch so if my think process is wrong here, pls let me know.

The issue:

My install steps (did it 3 times by the installation steps in here to be sure):

No security vulnerability advisories found
Using version ^6.0 for backpack/permissionmanager
/var/www/app # php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="migrations"

   INFO  No publishable resources for tag [migrations].

/var/www/app # php artisan migrate

   INFO  Nothing to migrate.

/var/www/app # php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="config"

   INFO  No publishable resources for tag [config].

/var/www/app # php artisan vendor:publish --provider="Backpack\PermissionManager\PermissionManagerServiceProvider" --tag="config" --tag="migrations"

   INFO  Publishing [config] assets.

  Copying directory [/var/www/vendor/backpack/permissionmanager/src/config] to [config] ....................................................... DONE

   INFO  Publishing [migrations] assets.

  Copying directory [/var/www/vendor/backpack/permissionmanager/src/database/migrations] to [database/migrations] ............................. DONE

/var/www/app # php artisan migrate

   INFO  Running migrations.

  2020_03_31_114745_remove_backpackuser_model ............................................................................................. 3ms DONE

/var/www/app # php artisan migrate

   INFO  Nothing to migrate.

For me Spatie\Permission\PermissionServiceProvider is not creating the local migration files. If i check in the verdor map, the 2 required migration files are there.

The issue is that the publish tags of spatie/laravel-permission changes, if you run:

php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="permission-config"  --tag="permission-migrations"

Then it works:

/var/www/app # php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="permission-config"  --tag="permission-migrations"
   INFO  Publishing [permission-config] assets.

  Copying file [/var/www/vendor/spatie/laravel-permission/config/permission.php] to [config/permission.php] ................................... DONE

   INFO  Publishing [permission-migrations] assets.

  Copying file [/var/www/vendor/spatie/laravel-permission/database/migrations/create_permission_tables.php.stub] to [database/migrations/2023_03_25_125123_create_permission_tables.php]  DONE

Hope this helps :-D

jcastroa87 commented 1 year ago

Hello, im sorry for late answer but we was going deeper on this issue.

Could you replace this instructions:

php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="migrations"
php artisan migrate
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="config"
// then, add the Spatie\Permission\Traits\HasRoles trait to your User model(s)

For this:

php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
php artisan migrate

Let us know if work normal, if thats is the answer we will working on update instructions or make fixed in pachage.

Thanks.

pxpm commented 1 year ago

This was fixed in https://github.com/Laravel-Backpack/PermissionManager/pull/321

Thanks guys for the help here 🙏

Cheers