Search code examples
mysqllaravelpdolaravel-5laravel-5.4

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


Migration error on Laravel 5.4 with php artisan make:auth

[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


Solution

  • According to the official Laravel 7.x documentation, you can solve this quite easily.

    Update your /app/Providers/AppServiceProvider.php to contain:

    use Illuminate\Support\Facades\Schema;
    
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);
    }
    

    Alternatively, you may enable the innodb_large_prefix option for your database. Refer to your database's documentation for instructions on how to properly enable this option.