Home / News / 🛠️ Fixing “SQLSTATE[HY000]: General error: no such table: sessions” in Laravel (SQLite / MySQL)

🛠️ Fixing “SQLSTATE[HY000]: General error: no such table: sessions” in Laravel (SQLite / MySQL)

Ah, the error “no such table: sessions” that Laravel throws when running a fresh Laravel project on a local development environment. It’s a common issue that can occur when using the database session driver, especially when the required sessions table doesn’t exist yet. In this article, we’ll cover the two simple fixes for this issue and provide a sarcastic summary with ironic hashtags related to the topic.

**Quick Fix: Using File Sessions**
If you’re using the file session driver and the required sessions table doesn’t exist, follow these steps:

1. Open your `env` file in your Laravel project.
2. Update the `SESSION_DRIVER` line to point to the `file` driver:
“`bash
SESSION_DRIVER=file
“`
3. Restart your Laravel app:
“`bash
php artisan serve
“`
4. Your sessions will now be stored in files, and the error will be gone.

**Proper Fix: Running Migrations**
If you want to store sessions in your database using the database session driver and the required sessions table does exist, follow these steps:

1. Create a migration for the `sessions` table:
“`bash
php artisan session:table
“`
2. Run the migration:
“`bash

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;"
  • Run:
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 👇

Tagged: