laravel/framework · error · RuntimeException

Extensions are only supported by Postgres.

Error message

Extensions are only supported by Postgres.

What it means

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.

Source

Thrown at src/Illuminate/Database/Schema/Builder.php:683

     */
    public function ensureVectorExtensionExists($schema = null)
    {
        $this->ensureExtensionExists('vector', $schema);
    }

    /**
     * Create a new extension on the schema if it does not exist.
     *
     * @param  string  $name
     * @param  string|null  $schema
     * @return void
     *
     * @throws \RuntimeException
     */
    public function ensureExtensionExists($name, $schema = null)
    {
        if (! $this->getConnection() instanceof PostgresConnection) {
            throw new RuntimeException('Extensions are only supported by Postgres.');
        }

        $name = $this->getConnection()->getSchemaGrammar()->wrap($name);

        $this->getConnection()->statement(match (filled($schema)) {
            true => "create extension if not exists {$name} schema {$this->getConnection()->getSchemaGrammar()->wrap($schema)}",
            false => "create extension if not exists {$name}",
        });
    }

    /**
     * Execute the blueprint to build / modify the table.
     *
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
     * @return void
     */
    protected function build(Blueprint $blueprint)
    {

View on GitHub (pinned to bd6b5437e6)

Solutions

  1. Switch the connection to Postgres if you need the extension (e.g. for pgvector).
  2. Remove the ensureExtensionExists / ensureVectorExtensionExists call from migrations that run against non-Postgres.
  3. Conditionally apply the migration using DB::connection() instanceof PostgresConnection.
  4. For vector columns specifically, use a driver-appropriate alternative (e.g. JSON/blob storage) on unsupported drivers.

Example fix

// before
Schema::ensureVectorExtensionExists();
Schema::create('embeddings', fn ($t) => $t->vector('embedding', 1536));

// after
if (DB::connection() instanceof \Illuminate\Database\PostgresConnection) {
    Schema::ensureVectorExtensionExists();
    Schema::create('embeddings', fn ($t) => $t->vector('embedding', 1536));
}
Defensive patterns

Strategy: validation

Validate before calling

if (! DB::connection() instanceof \Illuminate\Database\PostgresConnection) {
    throw new \RuntimeException('Extensions require a Postgres connection.');
}
Schema::ensureExtensionExists($name, $schema);

Type guard

function isPostgres(): bool
{
    return DB::connection() instanceof \Illuminate\Database\PostgresConnection;
}

Try / catch

try {
    Schema::ensureVectorExtensionExists();
} catch (\RuntimeException $e) {
    if (str_contains($e->getMessage(), 'only supported by Postgres')) {
        // skip on non-Postgres
    } else {
        throw $e;
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06). Data as JSON: /data/errors/f711cb714cf9bf3a.json. Report an issue: GitHub.