{"id":"fd12a87354ae757c","repo":"laravel/framework","slug":"this-database-engine-does-not-support-json-contain-fd12a8","errorCode":null,"errorMessage":"This database engine does not support JSON contains key operations.","messagePattern":"This database engine does not support JSON contains key operations\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Query/Grammars/Grammar.php","lineNumber":781,"sourceCode":"    {\n        $not = $where['not'] ? 'not ' : '';\n\n        return $not.$this->compileJsonContainsKey(\n            $where['column']\n        );\n    }\n\n    /**\n     * Compile a \"JSON contains key\" statement into SQL.\n     *\n     * @param  string  $column\n     * @return string\n     *\n     * @throws \\RuntimeException\n     */\n    protected function compileJsonContainsKey($column)\n    {\n        throw new RuntimeException('This database engine does not support JSON contains key operations.');\n    }\n\n    /**\n     * Compile a \"where JSON length\" clause.\n     *\n     * @param  \\Illuminate\\Database\\Query\\Builder  $query\n     * @param  array  $where\n     * @return string\n     */\n    protected function whereJsonLength(Builder $query, $where)\n    {\n        return $this->compileJsonLength(\n            $where['column'],\n            $where['operator'],\n            $this->parameter($where['value'])\n        );\n    }\n","sourceCodeStart":763,"sourceCodeEnd":799,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Query/Grammars/Grammar.php#L763-L799","documentation":"The base Grammar::compileJsonContainsKey() throws because this engine has no JSON key-existence predicate. All four bundled grammars (SQLite, MySQL, Postgres, SQL Server) override compileJsonContainsKey, so this base throw is only reached by a custom Grammar subclass that extends the base Grammar without the JSON key method.","triggerScenarios":"Calling whereJsonContainsKey($column) on a connection whose grammar does not override compileJsonContainsKey (i.e. a custom/third-party grammar). No bundled engine reaches this base method.","commonSituations":"Writing/testing a new database driver integration that extends Grammar but has not implemented the JSON key methods yet. Using a community package providing a grammar that is incomplete.","solutions":["Implement compileJsonContainsKey($column) on the custom Grammar with the engine's native JSON key-existence function.","Use one of the bundled drivers that supports the operation.","Replace whereJsonContainsKey with a whereRaw using the native JSON path/exists function."],"exampleFix":"// before (custom grammar)\n$q->whereJsonContainsKey('meta->enabled');\n// throws base Grammar::compileJsonContainsKey\n\n// after\nprotected function compileJsonContainsKey($column)\n{\n    return \"json_exists({$column})\";\n}","handlingStrategy":"validation","validationCode":"$driver = $query->getConnection()->getDriverName();\nif (! in_array($driver, ['mysql','sqlite','pgsql','sqlsrv'])) {\n    throw new \\LogicException('whereJsonContainsKey is not supported by this engine.');\n}\n$query->whereJsonContainsKey('meta->enabled');","typeGuard":"function supportsJsonContainsKey(\\Illuminate\\Database\\Connection $connection): bool\n{\n    return method_exists($connection->getQueryGrammar(), 'compileJsonContainsKey');\n}","tryCatchPattern":null,"preventionTips":["Complete the JSON method set when writing a custom grammar.","Use bundled drivers for JSON key-existence checks.","Add capability tests for any new driver integration."],"tags":["json","where-json-contains-key","custom-grammar","database-engine"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}