laravel/framework · error · RuntimeException

Index [ ] does not exist.

Error message

Index [{$command->from}] does not exist.

What it means

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.

Solutions

  1. Verify the index exists before renaming: query DB::connection()->getSchemaBuilder()->getIndexes('table') and confirm 'old_name'.
  2. Fix the source name in the renameIndex call to match the index that was actually created.
  3. Ensure migrations run in order so the index-creating migration precedes the rename migration.

Example fix

// before
$table->renameIndex('order_number_ind', 'orders_number_index'); // wrong source name

// after
$indexes = DB::connection()->getSchemaBuilder()->getIndexes('orders');
$source = collect($indexes)->firstWhere('name', /* real name */ 'orders_order_number_index');
$table->renameIndex($source['name'], 'orders_number_index');
Defensive patterns

Strategy: validation

Validate before calling

use Illuminate\Support\Facades\DB;

$indexes = DB::connection()->getSchemaBuilder()->getIndexes('orders');
$exists = collect($indexes)->contains(fn ($i) => $i['name'] === 'orders_number_index');

if ($exists) {
    $table->renameIndex('orders_number_index', 'orders_number_new_index');
}

Type guard

function indexExists(string $table, string $name): bool {
    return collect(\Illuminate\Support\Facades\DB::connection()->getSchemaBuilder()->getIndexes($table))
        ->contains(fn ($i) => $i['name'] === $name);
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11). Data as JSON: /api/errors/9a05317fba28e38b. Report an issue: GitHub.

Appendix: 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 e0f6eb3518)