I ran into a problem with laravel migration where I need to set index length for a specific column but it looks like Schema/Blueprint index() does not have such feature. Laravel Docs
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation:
1170 BLOB/TEXT column 'description' used in key specification
without a key length (SQL: alter table `Customers`
add index `description_idx`(`description`))
Original sql query line:
KEY `description_idx` (`description`(100)) // index length = 100
Laravel migration code line:
$table->text('description')->nullable()->index('`description_idx`'); // no index length here
At moment I feel the best I can do is to change column type, but maybe there is more appropriate way to fix this issue?
You can create these indexes manually using DB::statement(); in your migration.
In your up() do something like this
DB::statement('CREATE INDEX description_idx ON Customers (description(100));');
And then in your down() you can simply
Schema::table('Customers', function($table) {
$table->dropIndex('description_idx');
});
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With