1

In laravel 8 / mysql 5.7 defining table with index :

Schema::create('community', function (Blueprint $table) {
    $table->id();
    $table->string('question_title', 1000);
    $table->string('question_slug', 1005)->unique();

    $table->boolean('status')->default(false);
    $table->unsignedTinyInteger('question_point')->default(0);

    ...
    $table->index(['status', 'question_title'], 'community_status_question_title_index');
});

I got error :

  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 3072 bytes (SQL: alter table `community` add index `community_status_question_title_index`(`status`, `question_title`))

I wonder why limit in 3072 was broken, as question_title has 1000 chars length and status is bool and how it can be fixed ?

MODIFIED : I get decision from poinetd branch, but adding in file : /app/Providers/AppServiceProvider.php

use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}

I tried to modify value :

Schema::defaultStringLength(2000);

But got the same error anyway...

Thanks!

mstdmstd
  • 2,195
  • 17
  • 63
  • 140

0 Answers0