{"record":{"id":"9a05317fba28e38b","repo":"laravel/framework","slug":"index-command-from-does-not-exist","errorCode":null,"errorMessage":"Index [{$command->from}] does not exist.","messagePattern":"Index \\[(.+?)\\] does not exist\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php","lineNumber":643,"sourceCode":"    }\n\n    /**\n     * Compile a rename index command.\n     *\n     * @param  \\Illuminate\\Database\\Schema\\Blueprint  $blueprint\n     * @param  \\Illuminate\\Support\\Fluent  $command\n     * @return array\n     *\n     * @throws \\RuntimeException\n     */\n    public function compileRenameIndex(Blueprint $blueprint, Fluent $command)\n    {\n        $indexes = $this->connection->getSchemaBuilder()->getIndexes($blueprint->getTable());\n\n        $index = Arr::first($indexes, fn ($index) => $index['name'] === $command->from);\n\n        if (! $index) {\n            throw new RuntimeException(\"Index [{$command->from}] does not exist.\");\n        }\n\n        if ($index['primary']) {\n            throw new RuntimeException('SQLite does not support altering primary keys.');\n        }\n\n        if ($index['unique']) {\n            return [\n                $this->compileDropUnique($blueprint, new IndexDefinition(['index' => $index['name']])),\n                $this->compileUnique($blueprint,\n                    new IndexDefinition(['index' => $command->to, 'columns' => $index['columns']])\n                ),\n            ];\n        }\n\n        return [\n            $this->compileDropIndex($blueprint, new IndexDefinition(['index' => $index['name']])),\n            $this->compileIndex($blueprint,","sourceCodeStart":625,"sourceCodeEnd":661,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php#L625-L661","documentation":"SQLiteGrammar::compileRenameIndex asks the schema builder for the table's existing indexes, then looks for one whose name equals $command->from. If no index with that name exists, it throws RuntimeException. SQLite needs to look up the existing index because it cannot rename indexes in place — it must drop and recreate them, which requires knowing the columns and uniqueness.","triggerScenarios":"Calling $table->renameIndex('old_name', 'new_name') where 'old_name' was never created on the SQLite table (typo, already dropped, or created in a migration that did not run on this connection).","commonSituations":"Rename-index migration run out of order; index name typo; rollback/re-run against a partially-migrated SQLite database where the source index was never applied; tests using a stale :memory: schema.","solutions":["Verify the index exists before renaming: query DB::connection()->getSchemaBuilder()->getIndexes('table') and confirm 'old_name'.","Fix the source name in the renameIndex call to match the index that was actually created.","Ensure migrations run in order so the index-creating migration precedes the rename migration."],"exampleFix":"// before\n$table->renameIndex('order_number_ind', 'orders_number_index'); // wrong source name\n\n// after\n$indexes = DB::connection()->getSchemaBuilder()->getIndexes('orders');\n$source = collect($indexes)->firstWhere('name', /* real name */ 'orders_order_number_index');\n$table->renameIndex($source['name'], 'orders_number_index');","handlingStrategy":"validation","validationCode":"use Illuminate\\Support\\Facades\\DB;\n\n$indexes = DB::connection()->getSchemaBuilder()->getIndexes('orders');\n$exists = collect($indexes)->contains(fn ($i) => $i['name'] === 'orders_number_index');\n\nif ($exists) {\n    $table->renameIndex('orders_number_index', 'orders_number_new_index');\n}","typeGuard":"function indexExists(string $table, string $name): bool {\n    return collect(\\Illuminate\\Support\\Facades\\DB::connection()->getSchemaBuilder()->getIndexes($table))\n        ->contains(fn ($i) => $i['name'] === $name);\n}","tryCatchPattern":null,"preventionTips":["Verify the source index exists with getIndexes() before renameIndex on SQLite.","Keep migration order deterministic so the create runs before the rename.","Use the exact name from the create call; avoid typos."],"tags":["database","schema","migrations","sqlite","indexes","rename"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}