Error: SQLSTATE [42000]

1

I have the following error when executing

php artisan migrate

I'm using Lumen 5.6

  

In Connection.php line 664:                                                                                                                                                                                             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 ))

  

In Connection.php line 458:                                                                                                                         SQLSTATE [42000]: Syntax error or access violation: 1071 Specified key   was too long; max key length is 767 bytes

    
asked by Bryan Zavala 26.04.2018 в 23:58
source

2 answers

1

I already solved it in the following way:

I added the following lines of code in app/Providers/AppServiceProvider.php

use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}

Uncomment the following line of code in bootstrap/app.php on line 81;

$app->register(App\Providers\AppServiceProvider::class);
    
answered by 27.04.2018 / 00:08
source
1

At the time of migration, specify the length in the fields of type unique and type index, as follows:

public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email', 30)->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

As notes with a comma I pass a maximum length of 30 characters to that column with that should be solved

  

As a note I commented that this is also corrected by updating the mysql   to version 5.7; but be careful, that is only done if you have support from your   database because otherwise you can lose everything

    
answered by 27.04.2018 в 00:05