Laravel: Syntax error or access violation: 1071 Specified key was too long

0

I have created the tables in the database, but it shows me the error: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes .

How do I fix this?

    
asked by anonymous 28.01.2018 / 16:39

2 answers

2

This happens because Laravel changed the default value of the fields. To fix this, just go to the file app/Providers/AppServiceProvider.php and add the following code:

use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}
    
28.01.2018 / 16:42
0

Another way to solve is to add the index name in the second parameter:

$table->string('seu_campo')->unique(null,'chave');
    
24.07.2018 / 15:25