{"id":"cfbaf01e64330fff","repo":"laravel/framework","slug":"the-database-driver-in-use-does-not-support-spatia","errorCode":null,"errorMessage":"The database driver in use does not support spatial indexes.","messagePattern":"The database driver in use does not support spatial indexes\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php","lineNumber":440,"sourceCode":"            $schema ? $this->wrapValue($schema).'.' : '',\n            $this->wrap($command->index),\n            $this->wrapTable($table),\n            $this->columnize($command->columns)\n        );\n    }\n\n    /**\n     * Compile a spatial index key command.\n     *\n     * @param  \\Illuminate\\Database\\Schema\\Blueprint  $blueprint\n     * @param  \\Illuminate\\Support\\Fluent  $command\n     * @return void\n     *\n     * @throws \\RuntimeException\n     */\n    public function compileSpatialIndex(Blueprint $blueprint, Fluent $command)\n    {\n        throw new RuntimeException('The database driver in use does not support spatial indexes.');\n    }\n\n    /**\n     * Compile a foreign key command.\n     *\n     * @param  \\Illuminate\\Database\\Schema\\Blueprint  $blueprint\n     * @param  \\Illuminate\\Support\\Fluent  $command\n     * @return string|null\n     */\n    public function compileForeign(Blueprint $blueprint, Fluent $command)\n    {\n        // Handled on table creation or alteration...\n    }\n\n    /**\n     * Compile a drop table command.\n     *\n     * @param  \\Illuminate\\Database\\Schema\\Blueprint  $blueprint","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php#L422-L458","documentation":"SQLite does not support spatial indexes (no R-tree/spatial extension). SQLiteGrammar.compileSpatialIndex() unconditionally throws RuntimeException when a migration requests spatialIndex(). This is a hard driver-capability gate at compile time.","triggerScenarios":"Calling $table->spatialIndex('geom') or $table->spatialIndex(['col'], 'name') in a migration that executes against a SQLite connection. Common when the test suite uses :memory: SQLite but prod uses MySQL/Postgres with PostGIS.","commonSituations":"DB_CONNECTION=sqlite in testing while production uses MySQL with spatial data; a shared migrations folder used by both environments; a package that ships spatial indexes without driver guards.","solutions":["Guard the spatial index with the driver: if (Schema::getConnection()->getDriverName() !== 'sqlite') { $table->spatialIndex('geom'); }","Use Schema::connection('mysql') so the migration runs against the spatial-capable connection only.","For SQLite tests, substitute a normal index on the geometry column or skip the migration via a conditional."],"exampleFix":"// before\nSchema::create('places', function (Blueprint $table) {\n    $table->id();\n    $table->geometry('location');\n    $table->spatialIndex('location');\n});\n\n// after\nSchema::create('places', function (Blueprint $table) {\n    $table->id();\n    $table->geometry('location');\n    if ($table->getConnection()->getDriverName() !== 'sqlite') {\n        $table->spatialIndex('location');\n    }\n});","handlingStrategy":"validation","validationCode":"$driver = Schema::getConnection()->getDriverName();\nif ($driver !== 'sqlite') {\n    $table->spatialIndex('location');\n}","typeGuard":"function supportsSpatialIndex(Blueprint $table): bool\n{\n    return $table->getConnection()->getDriverName() !== 'sqlite';\n}","tryCatchPattern":null,"preventionTips":["Guard spatial indexes by driver in shared migrations.","Run migrations against SQLite in CI to catch driver-specific failures early.","Document driver assumptions in migration docblocks."],"tags":["database","schema","sqlite","migrations","spatial"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}