Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ifarooq's avatar

Laravel Composite Index Issue

In laravel 5.5 when I try to create a composite index of 3 columns it gives me following error while it works fine when I create composite index for two columns.

Syntax error or access violation: 1071 Specified key was t oo long; max key length is 1000 bytes

I am adding index using index method. $table->index(['column_1','column_2','column_3']);

I have also tried this. $table->index(['column_1','column_2','column_3'],"index_title");

column1 is int type and column_2 and column_3 are varchar

Please note that I have already added Schema::defaultStringLength(191); in AppServiceProvider.php

`public function boot(Request $request) { Schema::defaultStringLength(191);

}`

0 likes
5 replies
topvillas's avatar

Can you reduce the size of any of the columns making up the key?

rsvb's avatar

In mysql you can create an index and specify the length, so you keep the info in the column, but truncate it in the index.

ifarooq's avatar

@Snapey The length info is given below. 'column_1(int(11))','column_2(varchar(191))','column_3(varchar(191))'

@topvillas Yes the length of the column_2 and column_3 can be set to 50 but even if it is 191 the total length is 386 bytes which is less than 1000 bytes.

@Snapey Please let me know how can I specify length of the indexes in laravel migration file, like given here.

KEY index (parent_menu_id,menu_link(50),plugin(50),alias(50)) https://stackoverflow.com/questions/8746207/1071-specified-key-was-too-long-max-key-length-is-1000-bytes

Snapey's avatar

I dont know if you can fix the length in Laravel migration

The reason its struggling is that the strings are stored as utfmb4 so 191 character strings take up 4 times that in the Db

Perhaps you could use a DB raw command

Please or to participate in this conversation.