DEV Community

Chirag Patel
Chirag Patel

Posted on

Fixing "SQLSTATE[HY000]: General error: no such table: sessions" in Laravel (SQLite / MySQL)

If you’re running a fresh Laravel project and see this error:

Illuminate\Database\QueryException
SQLSTATE[HY000]: General error: 1 no such table: sessions
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
  • Restart your Laravel app:
php artisan serve
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Step 2: Run migrations

php artisan migrate
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
  • If the file doesn’t exist, create it:
touch database/database.sqlite
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
  • Create the database if it doesn’t exist:
mysql -u your_user -p -e "CREATE DATABASE your_db;"
Enter fullscreen mode Exit fullscreen mode
  • Run:
php artisan migrate
Enter fullscreen mode Exit fullscreen mode

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 👇

Top comments (0)