How to Fix Laravel Specified key was too long error

In this tutorial you will learn about the How to Fix Laravel Specified key was too long error and its application with practical example.

How to Fix Laravel Specified key was too long error

In Laravel, sometimes when we run the following command we get “Specified key was too long error” as shown in the below screenshot, in this tutorial I will show you how to fix the “Specified key was too long error” error.

laravel-crud-example-specified-key-too-long-error

Easiest way to fix error is to locate the file “app/Providers/AppServiceProvider”, and add following line of code to the top of the file

and inside the boot method set a default string length as given below –

So this is how my AppServiceProvider file looks like now –

Now delete tables created and run the following command again –

I hope this will fix “Specified key was too long error” error.

In this tutorial we have learn about the How to Fix Laravel Specified key was too long error and its application with practical example. I hope you will like this tutorial.