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

anonymouse703's avatar

How to solve this in session table?

I clone a project in 5.6 version and when run php artisan serve I have this error

Illuminate \ Database \ QueryException (42S22)
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user_id' in 'field list' (SQL: update `tb_sessions` set `payload` = YTozOntzOjY6Il90b2tlbiI7czo0MDoidWFyQzhZQ1p0S2JTWVA0VTdOQjhxUGo5VjFWMW5xYjNHTDBvNjlFZSI7czo5OiJfcHJldmlvdXMiO2E6MTp7czozOiJ1cmwiO3M6Mjc6Imh0dHA6Ly8xMjcuMC4wLjE6ODAwMC9sb2dpbiI7fXM6NjoiX2ZsYXNoIjthOjI6e3M6Mzoib2xkIjthOjA6e31zOjM6Im5ldyI7YTowOnt9fX0=, `last_activity` = 1626919736, `user_id` = , `ip_address` = 127.0.0.1, `user_agent` = Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36, `id` = s7wbQ8fUqzrhPJqErlzoa1r2HA75gwXpDjiK6mm0 where `id` = s7wbQ8fUqzrhPJqErlzoa1r2HA75gwXpDjiK6mm0)

I already run this php artisan cache:clear php artisan view:clear php artisan session:flush composer dump-autoload

I also truncate the session table but still I got this error

0 likes
10 replies
SilenceBringer's avatar

@anonymouse703 if you check the error

Column not found: 1054 Unknown column 'user_id' in 'field list'

so, check your tb_sessions has user_id column

If it has - check why user_id value is empty

user_id = ,

anonymouse703's avatar

Hello sir there's no user_id on the sessions table and the sessions table is empty...

siangboon's avatar

then either update the query to remove the user_id or change your database schema to add user_id column and pass the value accordingly and if so don't forget the add it to $fillable also...

but i believe user_id may be useful in this session case...

anonymouse703's avatar

The scenario is I only clone the project and upload the database... when I completely setup the pulled project and run the php artisan serve I got this error

Illuminate \ Database \ QueryException (42S22)
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user_id' in 'field list' (SQL: update `tb_sessions` set `payload` = YTozOntzOjY6Il90b2tlbiI7czo0MDoiYVQwaDBoSkZ3bWVIdjJqZjNMeWpCOUpYNkF6VDREVjJtUXNmNHFFYyI7czo5OiJfcHJldmlvdXMiO2E6MTp7czozOiJ1cmwiO3M6Mjc6Imh0dHA6Ly8xMjcuMC4wLjE6ODAwMC9sb2dpbiI7fXM6NjoiX2ZsYXNoIjthOjI6e3M6Mzoib2xkIjthOjA6e31zOjM6Im5ldyI7YTowOnt9fX0=, `last_activity` = 1626938042, `user_id` = , `ip_address` = 127.0.0.1, `user_agent` = Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36, `id` = 6ZatmCgiU8Sl2NaE8tP2fu8OaTutEu3cUymyqBpH where `id` = 6ZatmCgiU8Sl2NaE8tP2fu8OaTutEu3cUymyqBpH)
Previous exceptions
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user_id' in 'field list' (42S22)
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user_id' in 'field list' (42S22)

My thought first is this is a cache that needs to clear since the data on the error ``user_agent = Mozilla/5.0 (Windows NT 10.0; Win64; x64) but when I checked the database there's no data in sessions table.

So I cleared the config, view but still got the error

anonymouse703's avatar

I just delete session driver in the .env and it's running... I don't know where is the conflict in it.

SilenceBringer's avatar

@anonymouse703 default session driver is file (look at configs/session.php)

    'driver' => env('SESSION_DRIVER', 'file'),

in your .env it was

SESSION_DRIVER=database

so, when you removed it from the .env file - you stop using database for sessions. Of course problem is gone

anonymouse703's avatar

But what I did sir is I change database to file in the .env and clear the config but still the error occurred.

Please or to participate in this conversation.