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

masonzodiac's avatar

SQLSTATE[42S02]: Base table or view not found: 'table.cache' doesn't exist

Hello everyone

I recently changed CACHE_DRIVER of my current project in .env file to database.

Since I made this change, whenever I want to run php artisan migrate:fresh --seed OR php artisan migrate OR php artisan cache:clear. I receive this error:

SQLSTATE[42S02]: Base table or view not found: 'table.cache' doesn't exist.

IF I change CACHE_DRIVER back to file and I run php artisan migrate:fresh --seed it works and I can even clear cache using php artisan cache:clear with no errors!

Anyone know what is causing this problem? all table orders and migration looks correct to me but for some reason database doesn't work properly as cache_driver.

If anyone here has any possible solution please help me.

0 likes
18 replies
masonzodiac's avatar

@Tray2 Thank you for your help. I created cache and cache_locks tables. However I created these two tables using this command I found on Laravel website: php artisan cache:table. For now cache table is last file in migrations folder. It still doesn't work.

masonzodiac's avatar

@Tray2 Well if I run it to create new migration it works. If I clear all migrations and all existing tables then I run it, it doesn't work. So if I have an empty database and I run php artisan migrate it throws same error. But if I add one new table (e.g. create_jobs_table) it works.

Tray2's avatar

@soroosh I don't know what you mean by creating new migrations, why would you do that when you already have migrations?

Tray2's avatar

@soroosh I created a new project and switched to database cache without this issue

php artisan cache:table

   INFO  Migration created successfully.

php artisan migrate

   INFO  Preparing database.

  Creating migration table ..................................................................... 81ms DONE

   INFO  Running migrations.

  2014_10_12_000000_create_users_table ........................................................ 192ms DONE
  2014_10_12_100000_create_password_resets_table .............................................. 108ms DONE
  2019_08_19_000000_create_failed_jobs_table .................................................. 148ms DONE
  2019_12_14_000001_create_personal_access_tokens_table ....................................... 180ms DONE
  2022_12_29_184608_create_cache_table ........................................................ 259ms DONE
3 likes
Lara_Love's avatar

delete all table in phpmyadmin and run

php artisan migrate:refresh

Azade-ghasemi's avatar

I've fixed that problem. Go to the .env and change the value of SESSION_DRIVER into file

2 likes
Slym's avatar

Simply use the following command:

php artisan make:cache-table

Then you're good to go to migrating your cache table!

cjl2029's avatar

the .env file cache-driver=file

2 likes
stuartcusack's avatar

I only noticed this problem with Laravel 11. The new env var is called CACHE_STORE and I have to set it to file when working locally.

I'm not sure but I think Laravel 11 made database the default for caching, and this can cause problems when you haven't run your cache table migrations. You can't actually run your migrations because the error keeps occurring until you change to file - seems like a bug.

MuradAli's avatar

There are 2 solutions

  1. In the ENV file you will find CACHE_STORE, change it to CACHE_STORE=file
  2. You are using Cache at global level, might be possible somewhere inside the AppServiceProvider, so you can apply a check there, if (Schema::hasTable('cache'))
MarkusLenz's avatar

Hello everyone, I know, this post is 2 years old, but I have already the same issue. The solution is to configure all caches to file system and after the migration you can reset the settings to database, if you want.

But in my opinion this couldn't be the correct solution. Is there another solution I haven't cached yet?

Snapey's avatar

Can I just say that using the database for cache is a really bad idea, and no good for performance.

Please or to participate in this conversation.