Laravel 4 Migration Scheme - Index Length

I am having a problem with laravel migration where I need to set the index length for a specific column, but it looks like Schema / Blueprint index () does not have such a function. 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 

The moment I feel that the best thing I can do is change the type of the column, but maybe there is a more suitable way to fix this problem?

+6
source share
1 answer

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 just

 Schema::table('Customers', function($table) { $table->dropIndex('description_idx'); }); 

Hope this helps.

+8
source

Source: https://habr.com/ru/post/972358/


All Articles