Can you show your codes?
- the migration files and name
- the models
Or
A quick way to fix it is setting the table name
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Issue (Example):
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'role_users' doesn't exist (SQL: select count(*) as aggregate from role_users where role_id = 4)
The 3 tables are: roles, role_user, users
My understanding from the Laravel 8.x documentation is that "role_user" is the correct name to use. It works in most circumstances and is looked for correctly as "role_user".
Example of where I see it failing and looking for "role_users": RoleUser::where( 'role_id' , $role -> id ) -> count ( ) ; ^ This yields the message above. But why is it looking for "role_users" instead of "role_user"?
Open to thoughts, suggestions, etc.
Side note: 'grep -rai "role_users" ' yields no results (except those in the laravel.log file from the crashes).
Please or to participate in this conversation.