Laravel : Specified key was too long error

In Laravel made a change to the default database character set, and it’s now utf8mb4 which includes support for storing emojis.


This only affects new applications and as long as you are running MySQL v5.7.7 and higher you do not need to do anything.

[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table users add unique users_email_unique(email))

In the Migration fix this all you have to do is edit your app/Providers/AppServiceProvider.php file and inside the boot method set a default string length:

use Illuminate\Support\Facades\Schema;

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

After that everything should work normal.



No comments:

Post a Comment

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...