laravel error 1071 Specified key was too long

0

I have the problem of laravel of

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' a
dd unique 'users_email_unique'('email'))

And I've done what goes in laravel as a solution to go to App / providers and add a code and still follow the problem, even in migrations I put a length to the emails and I still throw the problem, to which Should it be?

Here AppServiceProvider.php code

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {

    Schema::defaultStringLength(191);

    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

Here is the code of the 2 migrations that Laravel brings by default, where I put the length.

migration of create_user_Table.php

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

And the create_password_reset.php

    public function up()
{
    Schema::create('password_resets', function (Blueprint $table) {
        $table->string('email', 250)->index();
        $table->string('token');
        $table->timestamp('created_at')->nullable();
    });
}
    
asked by Victor Escalona 02.05.2018 в 06:59
source

1 answer

0

I already found the solution, just by adding in AppServiceProvider.php

public function boot()
    {

    Schema::defaultStringLength(191);

    }

It is enough, if a length was previously placed in the emails of the migrations, it must be removed but it will continue to throw the error 1071.

    
answered by 02.05.2018 в 07:09