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.
@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.
@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.
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.
In the ENV file you will find CACHE_STORE, change it to CACHE_STORE=file
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'))
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?