Syntax error or access violation: 1071 Specified key was too long

Syntax error or access violation: 1071 Specified key was too long
  • Save

Error come while migrate command run on laravel

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

Solution

Go to file: /app/Providers/AppServiceProvider.php

and import schema namespace

use Illuminate\Support\Facades\Schema;

Add below line under boot() function

Schema::defaultStringLength(191);

IF It does not work for you Use this method

Inside config/database.php, replace this line for mysql

REPLACE

'engine' => null',

to

'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',

Run migration command again. you will get success

  • Save