-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sanctum Cannot Find Existing Database Table When Using Sanctum::usePersonalAccessTokenModel() #555
Comments
Hey there, thanks for reporting this issue. We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.
Do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue. Thanks! |
@crynobone Just created and pushed the repo. I tested it locally using SQLite and could not reproduce the issue. I then tested it gain using a MySQL database and was able to reproduce the issue. Please let me know if you need anything more from me. |
Will check this out tomorrow |
Thank you! There's no rush. We made the necessary production changes to accommodate this bug in the meantime, but we eventually would like to restore our naming convention rather than having a single stray table. Appreciate your help! |
How should I run the app to generate the error. It doesn't seem to provide any seeds to generate rows to |
I created the user and the token using Tinker in the terminal. Let me know if you want me to add seeders to the repo. |
If you can create the token, doesn't that mean everything working correctly? A seeder would be good here |
Normally, yes, I would say everything is working, but this issue arises when an API request is received by the application, not when the token is being created. It's odd behavior. I'll have time to create the seeder this afternoon. |
Just pushed the creation of the API Token to the seeder. |
Sanctum Version
4.0.7
Laravel Version
11.38.2
PHP Version
8.3
Database Driver & Version
MySQL 8
Description
When customizing the
personal_access_tokens
table name via a Model Override per the documentation and then making a request to an API, an error is displayed statingSQLSTATE[42S02]: Base table or view not found: 1146 Table 'servicepoint_sp1_dev.personal_access_tokens' doesn't exist (Connection: mysql, SQL: select * from
personal_access_tokenswhere
personal_access_tokens.
id= 1 limit 1)
The odd thing is that if I change the table name from my custom name of
sys_personal_access_tokens
back to the default ofpersonal_access_tokens
the issue remains, except now Sanctum is complaining that it cannot find the database table with the custom name.The only way I've been able to workaround this issue is by changing the database table name back to
personal_access_tokens
and removingSanctum::usePersonalAccessTokenModel(CustomPersonalAccessToken::class);
from myAppServiceProvider
Steps To Reproduce
AppServiceProvider
withSanctum::usePersonalAccessTokenModel(CustomPersonalAccessToken::class);
sys_personal_access_tokens
topersonal_access_tokens
The text was updated successfully, but these errors were encountered: