{"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/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php#L625-L661","documentation":"SQLiteGrammar.compileRenameIndex() throws RuntimeException when the index named in $command->from is not found in the table's existing indexes. SQLite implements renameIndex via drop+recreate, so it must look up the existing index first; a missing index is a real, recoverable configuration error rather than a capability gap.","triggerScenarios":"Calling $table->renameIndex('old_name', 'new_name') where 'old_name' does not exist on the table — due to a typo, the index already being renamed in a prior migration, or out-of-order migration execution. The grammar queries getIndexes() and finds no match.","commonSituations":"Migration ordering bugs (rename runs before the index is created); typos in index names; running a subset of migrations; index created in a separate connection/schema; stale migration state after a failed prior run.","solutions":["Verify the index exists first: Schema::getConnection()->getSchemaBuilder()->getIndexes('table') and confirm the name.","Fix the from-name to match the actually-created index name (Laravel auto-generates names like '{table}_{columns}_index').","Ensure migrations run in order; check that the creating migration precedes the renaming one.","If the index may or may not exist, guard with hasIndex() before renaming."],"exampleFix":"// before — typo / wrong name\nSchema::table('users', function (Blueprint $table) {\n    $table->renameIndex('users_email_uniquex', 'users_email_idx');\n});\n\n// after — verify then rename\n$builder = Schema::getConnection()->getSchemaBuilder();\nif (collect($builder->getIndexes('users'))->contains(fn ($i) => $i['name'] === 'users_email_unique')) {\n    Schema::table('users', function (Blueprint $table) {\n        $table->renameIndex('users_email_unique', 'users_email_idx');\n    });\n}","handlingStrategy":"validation","validationCode":"$builder = Schema::getConnection()->getSchemaBuilder();\n$exists = collect($builder->getIndexes('users'))\n    ->contains(fn ($i) => $i['name'] === 'old_name');\nif ($exists) {\n    Schema::table('users', fn (Blueprint $t) => $t->renameIndex('old_name', 'new_name'));\n}","typeGuard":"function indexExists(string $table, string $name): bool\n{\n    return collect(Schema::getConnection()->getSchemaBuilder()->getIndexes($table))\n        ->contains(fn ($i) => $i['name'] === $name);\n}","tryCatchPattern":"try {\n    Schema::table('users', fn (Blueprint $t) => $t->renameIndex('old_name', 'new_name'));\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'does not exist')) {\n        // index already gone or never created — log and continue\n    } else { throw $e; }\n}","preventionTips":["Verify index names before renaming, especially after refactors.","Keep create/rename migrations strictly ordered.","Use Laravel's auto-generated index names to avoid typos."],"tags":["database","schema","sqlite","migrations","indexes"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}