JaredDev Logo

MySQL DB/MariaDB Fix UTF-8 Max String Field Length in Laravel


The Issue

With Laravel defaulting to UTF-8 you now need to specify the default max length for your fields with a type of string that you create during migrations.

The Error

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

You will see an error similar to the one above if this applies to you. Luckily the fix is incredibly easy!

The Fix

In app > Providers > AppServiceProvider.php you'll need to update your boot() method to the following...

public function boot()
    // ...other code...
    // ...other code...

And your done!

Now you should be able to run your migrations without any issue!