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();
});
}