laravel/framework · error · RuntimeException

The database driver in use does not support spatial indexes.

Error message

The database driver in use does not support spatial indexes.

What it means

SQLiteGrammar::compileSpatialIndex unconditionally throws because SQLite (without the SpatiaLite extension, which Laravel does not wire up) has no native spatial index command. Blueprint->spatialIndex() dispatches to this compiler method on a SQLite connection and fails immediately.

Solutions

  1. Run the migration against Postgres or MySQL (5.7+/MariaDB) where spatialIndex compiles to SPATIAL INDEX.
  2. Gate the spatial index by connection type so SQLite test runs skip it: if (! DB::connection() instanceof \Illuminate\Database\SQLiteConnection) { $table->spatialIndex('geom'); }.
  3. In tests, use the RefreshDatabase trait with a Postgres/MySQL test database or skip the offending migration via Schema::getConnection()->getDriverName() checks.

Example fix

// before
$table->spatialIndex('location');

// after (driver-gated)
use Illuminate\Support\Facades\DB;

if (DB::connection()->getDriverName() !== 'sqlite') {
    $table->spatialIndex('location');
}
Defensive patterns

Strategy: validation

Validate before calling

use Illuminate\Support\Facades\DB;

if (DB::connection()->getDriverName() !== 'sqlite') {
    $table->spatialIndex('location');
}

Type guard

function supportsSpatialIndex(?\Illuminate\Database\ConnectionInterface $c = null): bool {
    $c ??= \Illuminate\Support\Facades\DB::connection();
    return in_array($c->getDriverName(), ['mysql', 'mariadb', 'pgsql'], true);
}

Prevention

When it happens

Trigger: Calling $table->spatialIndex('geom') or ->spatialIndex(['lat','lng']) while the Schema connection is SQLite (e.g. the default testing or in-memory connection).

Common situations: Running migration tests against :memory: SQLite but the production migration uses Postgres/MySQL spatial indexes; CI configured with SQLite while staging/prod use a spatial-capable database.

Related errors


AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11). Data as JSON: /api/errors/cfbaf01e64330fff. Report an issue: GitHub.

Appendix: source

Thrown at src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php:440

            $schema ? $this->wrapValue($schema).'.' : '',
            $this->wrap($command->index),
            $this->wrapTable($table),
            $this->columnize($command->columns)
        );
    }

    /**
     * Compile a spatial index key command.
     *
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
     * @param  \Illuminate\Support\Fluent  $command
     * @return void
     *
     * @throws \RuntimeException
     */
    public function compileSpatialIndex(Blueprint $blueprint, Fluent $command)
    {
        throw new RuntimeException('The database driver in use does not support spatial indexes.');
    }

    /**
     * Compile a foreign key command.
     *
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
     * @param  \Illuminate\Support\Fluent  $command
     * @return string|null
     */
    public function compileForeign(Blueprint $blueprint, Fluent $command)
    {
        // Handled on table creation or alteration...
    }

    /**
     * Compile a drop table command.
     *
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint

View on GitHub (pinned to e0f6eb3518)