Laravel Error: Specified key was too long error

When you run php artisan:migrate on Windows Machine and instead of Running the Migration, there is 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 table 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 

Just put the following line in the register() method of app\Providers\AppServiceProvider.php


  

use Illuminate\Support\Facades\Schema;
 public function register()
    {
        Schema::defaultStringLength(191);
    }


 

And then run php artisan migrate

Note this problem is with older versions of MySql so you should rather upgrade your mysql installation rather then doing this hack.

No comments:

Post a Comment

Running Drupal in Docker

I will assume that you have already installed docker. If you haven't installed docker please visit https://www.docker.com/ to download a...