laravel/framework · error · RuntimeException
Index [{$command->from}] does not exist.
Error message
Index [{$command->from}] does not exist. What it means
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.
Source
Thrown at src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php:643
}
/**
* Compile a rename index command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return array
*
* @throws \RuntimeException
*/
public function compileRenameIndex(Blueprint $blueprint, Fluent $command)
{
$indexes = $this->connection->getSchemaBuilder()->getIndexes($blueprint->getTable());
$index = Arr::first($indexes, fn ($index) => $index['name'] === $command->from);
if (! $index) {
throw new RuntimeException("Index [{$command->from}] does not exist.");
}
if ($index['primary']) {
throw new RuntimeException('SQLite does not support altering primary keys.');
}
if ($index['unique']) {
return [
$this->compileDropUnique($blueprint, new IndexDefinition(['index' => $index['name']])),
$this->compileUnique($blueprint,
new IndexDefinition(['index' => $command->to, 'columns' => $index['columns']])
),
];
}
return [
$this->compileDropIndex($blueprint, new IndexDefinition(['index' => $index['name']])),
$this->compileIndex($blueprint,View on GitHub (pinned to bd6b5437e6)
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.
Example fix
// before — typo / wrong name
Schema::table('users', function (Blueprint $table) {
$table->renameIndex('users_email_uniquex', 'users_email_idx');
});
// after — verify then rename
$builder = Schema::getConnection()->getSchemaBuilder();
if (collect($builder->getIndexes('users'))->contains(fn ($i) => $i['name'] === 'users_email_unique')) {
Schema::table('users', function (Blueprint $table) {
$table->renameIndex('users_email_unique', 'users_email_idx');
});
} Defensive patterns
Strategy: validation
Validate before calling
$builder = Schema::getConnection()->getSchemaBuilder();
$exists = collect($builder->getIndexes('users'))
->contains(fn ($i) => $i['name'] === 'old_name');
if ($exists) {
Schema::table('users', fn (Blueprint $t) => $t->renameIndex('old_name', 'new_name'));
} Type guard
function indexExists(string $table, string $name): bool
{
return collect(Schema::getConnection()->getSchemaBuilder()->getIndexes($table))
->contains(fn ($i) => $i['name'] === $name);
} Try / catch
try {
Schema::table('users', fn (Blueprint $t) => $t->renameIndex('old_name', 'new_name'));
} catch (\RuntimeException $e) {
if (str_contains($e->getMessage(), 'does not exist')) {
// index already gone or never created — log and continue
} else { throw $e; }
} Prevention
- Verify index names before renaming, especially after refactors.
- Keep create/rename migrations strictly ordered.
- Use Laravel's auto-generated index names to avoid typos.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- This database driver does not support fulltext index creatio
- This database driver does not support fulltext index removal
- The database driver in use does not support spatial indexes.
- This database driver does not support dropping foreign keys
- SQLite does not support altering primary keys.
AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06).
Data as JSON: /data/errors/9a05317fba28e38b.json.
Report an issue: GitHub.