If youâre running a fresh Laravel project and see this error:
Illuminate\Database\QueryException
SQLSTATE[HY000]: General error: 1 no such table: sessions
donât panic. This happens a lot when Laravel is using the database session driver but the required sessions table doesnât exist yet.
In this post, weâll go through why this happens and the two simple fixes (works for both SQLite and MySQL).
Why Does This Happen?
Laravel stores session data using different drivers. Common options include:
-
file
â stores sessions in storage/framework/sessions (default). -
database
â stores sessions in a sessions database table.
If your .env
has:
SESSION_DRIVER=database
Laravel expects a sessions
table in your database. If the table doesnât exist â youâll see the error.
Solution 1: Quick Fix (Use File Sessions)
For local development, you donât usually need database sessions.
- Open your
.env
file. - Update this line:
SESSION_DRIVER=file
- Restart your Laravel app:
php artisan serve
Thatâs it â your sessions will now be stored in files, and the error will be gone.
Solution 2: Proper Fix (Use Database Sessions)
If you want sessions stored in your database (recommended for production):
Step 1: Create the migration
php artisan session:table
Step 2: Run migrations
php artisan migrate
Now Laravel will create the sessions
table in your database.
SQLite Users
If youâre on the default SQLite setup:
- Make sure
.env
points to your database file:
DB_CONNECTION=sqlite
DB_DATABASE=/absolute/path/to/database.sqlite
- If the file doesnât exist, create it:
touch database/database.sqlite
Then re-run migrations.
MySQL Users
If you switched to MySQL in .env
:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_db
DB_USERNAME=your_user
DB_PASSWORD=your_password
- Create the database if it doesnât exist:
mysql -u your_user -p -e "CREATE DATABASE your_db;"
php artisan migrate
This will create the sessions
table inside your MySQL database.
Wrap Up
The error “no such table: sessions” in Laravel comes from using the database
session driver without running the migrations.
-
Quick dev fix â use
SESSION_DRIVER=file
-
Production fix â run
php artisan session:table && php artisan migrate
Once thatâs done, your app should work smoothly đ
đ Pro tip: If youâre just getting started, stick with file
sessions for local dev. Switch to database
sessions later when deploying to staging/production.
đĄ Whatâs your go-to session driver in Laravel projects â file
, database
, or maybe redis
? Drop your preference in the comments đ