Laravel Migration Error

Laravel Migration Error

When you migrate site in laravel with the CLI, Usually there is one error which you have phased during migration.

Here is the error which I got always while migrate in laravel.

Laravel Migration Error: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes.

So for the above problem you need to add following code in your AppServiceProvider.php file

Add following code to your or download AppServiceProvider.php and put it in /app/Providers/AppServiceProvider.php folder

use Illuminate\Support\Facades\Schema; //NEW: Import Schema

function boot(){

Schema::defaultStringLength(191); //Increase StringLength

}

MySQL reserves always the max amount for a UTF8 field which is 4 bytes so with 255 + 255 with your DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; you are over the 767 max key length limit.

So basically you may need to add in one file and you can migrate site again and you will able to migrate DB successfully.

I hope this will helps you to solve your problems while phasing issue in migration.

Thank you😃😃😊