Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Randy_Johnson's avatar

DB Column not found!?

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'model_has_roles.modal_id' in 'on clause' (SQL: select `users`.*, `model_has_roles`.* from `users` inner join `model_has_roles` on `users`.`id` = `model_has_roles`.`modal_id`) 
        $data = DB::table('users')
            ->join('model_has_roles', 'users.id', '=', 'model_has_roles.model_id')
            ->select('users.*', 'model_has_roles.*')
            ->get();
+---------+-----------------+----------+
| role_id | model_type      | model_id |
+---------+-----------------+----------+
|       1 | App\Models\User |        1 |
+---------+-----------------+----------+
+-----------------------+
| Tables_in_school      |
+-----------------------+
| attendances           |
| failed_jobs           |
| fees                  |
| grades                |
| injuries              |
| migrations            |
| model_has_permissions |
| model_has_roles       |
| password_resets       |
| payments              |
| permissions           |
| reports               |
| role_has_permissions  |
| roles                 |
| subjects              |
| time_tables           |
| users                 |
+-----------------------+
0 likes
3 replies
Randy_Johnson's avatar
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'model_has_roles.modal_id' in 'on clause' (SQL: select `users`.*, `model_has_roles`.* from `users` inner join `model_has_roles` on `users`.`id` = `model_has_roles`.`model_id`)

Sorry guys, it was really strange because I had changed that error, but it didn't refresh just right, I don't know why.

automica's avatar

@randy_johnson your error seems to relate to a spelling mismatch between modal_id and model_id.

In the supplied query, I can’t see that now being an issue.

If that is continuing to throw the same error, clear your caches and see if you get the same issue. Check also that the column in your current table is model_id not modal_id - it maybe you corrected it but failed to rerun your migrations

Please or to participate in this conversation.