Laravel12查看任务调度 php artisan schedule:list报错SQLSTATE[42S02]: Base table or view not found: 1146 Table laravel.cache_locks' doesn't exist 解决方法

4天前   阅读:122   类型:后端   分类:Laravel    标签: PHP Laravel

一、什么Laravel任务调度

Laravel 的命令调度器提供了一种全新的方法来管理服务器上的定时任务。调度器允许您在 Laravel 应用程序本身中流畅且有表达力地定义命令调度。

二、遇到问题

写完任务调度代码之后,查看调度任务和它们下一次计划运行的概况,使用 schedule:list Artisan 命令:

php artisan schedule:list

报如下错误:

Illuminate\Database\QueryException


SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel12.cache_locks' doesn't exist (Connection: mysql, SQL: update `cache_locks` set `owner` = SxRnJgzKqHTx6Z6n, `expiration` = 1743149223 where `key` = laravel_cache_framework\schedule-0dd41b6cf46707cbf5b912f0cf0cf936b5618f01 and (`owner` = SxRnJgzKqHTx6Z6n or `expiration` <= 1743062823))


at vendor\laravel\framework\src\Illuminate\Database\Connection.php:823

819▕ $this->getName(), $query, $this->prepareBindings($bindings), $e

820▕ );

821▕ }

822▕

➜ 823▕ throw new QueryException(

824▕ $this->getName(), $query, $this->prepareBindings($bindings), $e

825▕ );

826▕ }

827▕ }


1 [internal]:0

Illuminate\Console\Scheduling\ScheduleListCommand::Illuminate\Console\Scheduling\{closure}(Object(Illuminate\Console\Scheduling\Event))


2 vendor\laravel\framework\src\Illuminate\Database\Connection.php:590

PDOException::("SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel12.cache_locks' doesn't exist")

三、问题原因

遇到的错误表示 Laravel 在查询 cache_locks 表时,发现该表不存在。通常这是因为使用了 Laravel 的调度程序并启用了缓存锁定机制,但缺少了该表。

四、解决方法

1、方法一

创建缺失的表:Laravel 会使用一个名为 cache_locks 的表来管理调度任务的锁定机制。当使用数据库缓存时,Laravel 期望该表存在。你可以通过运行以下 Artisan 命令来生成创建表的迁移文件:

php artisan cache:table

这会生成一个迁移文件,用于创建 cache_locks 表。

运行迁移:生成迁移文件后,你需要运行它来在数据库中创建该表:

php artisan migrate

2、方法二

修改env配置文件,找到

CACHE_STORE=database

将其改为如下

CACHE_STORE=file

这里把他设置为文件,因为laravel12默认把存储方式设置为database数据库,我们改为file文件就可以。再次执行,就不在报错了。

【腾讯云】春季大促,助力开工,2核2G云服务器低至 68元/年

‘简忆博客’微信公众号 扫码关注‘简忆博客’微信公众号,获取最新文章动态
转载:请说明文章出处“来源简忆博客”。http://tpxhm.com/adetail/1139.html

×
觉得文章有用就打赏一下文章作者
微信扫一扫打赏 微信扫一扫打赏
支付宝扫一扫打赏 支付宝扫一扫打赏

文章评论(0)

登录
简忆博客壁纸一
简忆博客壁纸二
简忆博客壁纸三
简忆博客壁纸四
简忆博客壁纸五
简忆博客壁纸六
简忆博客壁纸七
简忆博客壁纸八
头像

简忆博客
勤于学习,乐于分享

置顶推荐

打赏本站

如果你觉得本站很棒,可以通过扫码支付打赏哦!
微信扫码:你说多少就多少~
微信扫码
支付宝扫码:你说多少就多少~
支付宝扫码
×