{"record":{"id":"263a8b06702e388e","repo":"laravel/framework","slug":"flushing-locks-is-only-supported-when-the-lock-sto-263a8b","errorCode":null,"errorMessage":"Flushing locks is only supported when the lock store is separate from the cache store.","messagePattern":"Flushing locks is only supported when the lock store is separate from the cache store\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"warning","filePath":"src/Illuminate/Cache/DatabaseStore.php","lineNumber":465,"sourceCode":"     */\n    public function flush()\n    {\n        $this->table()->delete();\n\n        return true;\n    }\n\n    /**\n     * Remove all locks from the store.\n     *\n     * @return bool\n     *\n     * @throws \\RuntimeException\n     */\n    public function flushLocks(): bool\n    {\n        if (! $this->hasSeparateLockStore()) {\n            throw new RuntimeException('Flushing locks is only supported when the lock store is separate from the cache store.');\n        }\n\n        $this->lockTable()->delete();\n\n        return true;\n    }\n\n    /**\n     * Get a query builder for the cache table.\n     *\n     * @return \\Illuminate\\Database\\Query\\Builder\n     */\n    protected function table()\n    {\n        return $this->connection->table($this->table);\n    }\n\n    /**","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Cache/DatabaseStore.php#L447-L483","documentation":"DatabaseStore::flushLocks deletes all rows from the cache locks table but only when the lock store is separate from the cache store (different DB connection/table). When locks share the cache table, flushing locks would delete cache entries, so the operation is refused. hasSeparateLockStore() is true only when a separate lock connection or lock table was provided.","triggerScenarios":"Calling Cache::store('database')->flushLocks() when the database cache store was constructed without a separate lock_table or lock_connection. Common when CACHE_LOCK_STORE is not set and the default database cache driver is reused for locks.","commonSituations":"Test or admin script calling Cache::flushLocks() to clear stuck locks while using the database cache driver without a dedicated locks table. Production using the same database table for cache and locks (the default) to save migrations.","solutions":["Configure a separate lock store by setting 'lock_connection' and/or 'lock_table' in the database cache store config in config/cache.php.","Set CACHE_LOCK_STORE env to point at a distinct cache store (e.g., 'redis') so hasSeparateLockStore() returns true.","If you only need to clear specific locks, release them via $lock->release() or DB::table('cache_locks')->where('key', $key)->delete() instead of flushLocks()."],"exampleFix":"// before (config/cache.php)\n'stores' => [\n    'database' => [\n        'driver' => 'database',\n        'table' => 'cache',\n        'connection' => null,\n        // no lock_connection/lock_table\n    ],\n],\n\n// after\n'stores' => [\n    'database' => [\n        'driver' => 'database',\n        'table' => 'cache',\n        'connection' => null,\n        'lock_connection' => null,\n        'lock_table' => 'cache_locks',\n    ],\n],\n// Run: php artisan cache:table && php artisan migrate","handlingStrategy":"validation","validationCode":"// Validate the database store has separate lock storage before flushing\n$store = Cache::store('database')->getStore();\nif (! $store->hasSeparateLockStore()) {\n    // release individual locks or skip\n    return;\n}\n$store->flushLocks();","typeGuard":"function databaseStoreHasSeparateLockStore(\\Illuminate\\Cache\\DatabaseStore $store): bool\n{\n    return $store->hasSeparateLockStore();\n}","tryCatchPattern":null,"preventionTips":["Always configure 'lock_table' (and optionally 'lock_connection') when using the database cache driver.","Run php artisan cache:table to publish both cache and cache_locks migrations.","Document that flushLocks() requires the separate lock table configuration.","Use Cache::lock()->release() for targeted cleanup instead of flushLocks()."],"tags":["cache","database","locks","configuration"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}