{"id":"f711cb714cf9bf3a","repo":"laravel/framework","slug":"extensions-are-only-supported-by-postgres","errorCode":null,"errorMessage":"Extensions are only supported by Postgres.","messagePattern":"Extensions are only supported by Postgres\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Schema/Builder.php","lineNumber":683,"sourceCode":"     */\n    public function ensureVectorExtensionExists($schema = null)\n    {\n        $this->ensureExtensionExists('vector', $schema);\n    }\n\n    /**\n     * Create a new extension on the schema if it does not exist.\n     *\n     * @param  string  $name\n     * @param  string|null  $schema\n     * @return void\n     *\n     * @throws \\RuntimeException\n     */\n    public function ensureExtensionExists($name, $schema = null)\n    {\n        if (! $this->getConnection() instanceof PostgresConnection) {\n            throw new RuntimeException('Extensions are only supported by Postgres.');\n        }\n\n        $name = $this->getConnection()->getSchemaGrammar()->wrap($name);\n\n        $this->getConnection()->statement(match (filled($schema)) {\n            true => \"create extension if not exists {$name} schema {$this->getConnection()->getSchemaGrammar()->wrap($schema)}\",\n            false => \"create extension if not exists {$name}\",\n        });\n    }\n\n    /**\n     * Execute the blueprint to build / modify the table.\n     *\n     * @param  \\Illuminate\\Database\\Schema\\Blueprint  $blueprint\n     * @return void\n     */\n    protected function build(Blueprint $blueprint)\n    {","sourceCodeStart":665,"sourceCodeEnd":701,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Schema/Builder.php#L665-L701","documentation":"Builder::ensureExtensionExists() hard-checks that the connection is a PostgresConnection (Builder.php:682) and throws RuntimeException otherwise, because 'CREATE EXTENSION' is a Postgres-only DDL feature. ensureVectorExtensionExists() delegates here, so vector usage on non-Postgres also surfaces this message.","triggerScenarios":"Calling Schema::ensureExtensionExists($name) or Schema::ensureVectorExtensionExists($schema) on a MySQL, SQLite, or SQL Server connection; running a migration that calls $table->vector() whose blueprint invokes ensureVectorExtensionExists on a non-Postgres driver.","commonSituations":"Copy-pasting a Postgres migration (using pgvector/vector extension) into a MySQL or SQLite project; CI test DB defaulted to SQLite while migrations assume Postgres extensions.","solutions":["Switch the connection to Postgres if you need the extension (e.g. for pgvector).","Remove the ensureExtensionExists / ensureVectorExtensionExists call from migrations that run against non-Postgres.","Conditionally apply the migration using DB::connection() instanceof PostgresConnection.","For vector columns specifically, use a driver-appropriate alternative (e.g. JSON/blob storage) on unsupported drivers."],"exampleFix":"// before\nSchema::ensureVectorExtensionExists();\nSchema::create('embeddings', fn ($t) => $t->vector('embedding', 1536));\n\n// after\nif (DB::connection() instanceof \\Illuminate\\Database\\PostgresConnection) {\n    Schema::ensureVectorExtensionExists();\n    Schema::create('embeddings', fn ($t) => $t->vector('embedding', 1536));\n}","handlingStrategy":"validation","validationCode":"if (! DB::connection() instanceof \\Illuminate\\Database\\PostgresConnection) {\n    throw new \\RuntimeException('Extensions require a Postgres connection.');\n}\nSchema::ensureExtensionExists($name, $schema);","typeGuard":"function isPostgres(): bool\n{\n    return DB::connection() instanceof \\Illuminate\\Database\\PostgresConnection;\n}","tryCatchPattern":"try {\n    Schema::ensureVectorExtensionExists();\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'only supported by Postgres')) {\n        // skip on non-Postgres\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Only call ensureExtensionExists()/ensureVectorExtensionExists() on Postgres.","Keep CI driver aligned with production driver for migrations using extensions.","Guard extension/vector migrations with instanceof PostgresConnection."],"tags":["schema","database","postgres","extensions","vector","driver-support"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}