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

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

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

In your first Laravel  project there have a common length or Syntax error or access violation: 1071 Specified key was too long error , occurs in artisan auth 

php artisan make:auth

After this command it show this error.

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

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

For this common error there have an easy solution just follow this code and past it into the boot function.

1st step: Add following code to 

AppServiceProvider.php (/app/Providers/AppServiceProvider.php)

2nd step: past this code into the   AppServiceProvider.php on top of the page.

use Illuminate\Support\Facades\Schema; //NEW: Import Schema
3rd step: Past this code into boot() function see blew example.

function boot()
{
    Schema::defaultStringLength(191); //NEW: Increase StringLength
}
4th step: Now save file and now re-type our artisan command.
Before re-type : 

php artisan make:auth

Delete all table user table from your database/ such as phpmyadmin table.
Now your code will work fine. (thanks for with us.)


  • laravel error handle
  • laravel Syntax error
  • access violation: 1071 laravel
  • 1071 Specified key was too long
  • Laravel Migration Error
  • Comments