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
- Run the migration against Postgres or MySQL (5.7+/MariaDB) where spatialIndex compiles to SPATIAL INDEX.
- Gate the spatial index by connection type so SQLite test runs skip it: if (! DB::connection() instanceof \Illuminate\Database\SQLiteConnection) { $table->spatialIndex('geom'); }.
- 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
- Guard spatial index creation by driver name.
- Run the production migration's tests against a spatial-capable DB.
- Use a separate test connection for spatial features rather than SQLite :memory:.
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
- SQLite does not support altering primary keys.
- This database driver does not support dropping foreign keys…
- This database driver requires a type, see the virtualAs /…
- Index [ ] does not exist.
- This database driver does not support modifying generated…
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 $blueprintView on GitHub (pinned to e0f6eb3518)