Php Artisan migration failed Laravel

I have the following error. Someone understands why?

php artisan migrate

 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`))

      

create_users_table.php

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

      

+3


source to share


3 answers


you need to edit the AppServiceProvider.php file in App\Providers\AppServiceProvider

and inside the upload method set the default line length:

use Illuminate\Support\Facades\Schema;

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

      



Then drop the database manually, then composer dump-autoload

andphp artisan migrate

+1


source


Change the AppServiceProvider.php

file, you will find this file inapp/Providers/AppServiceProvider.php

use Illuminate\Support\Facades\Schema;

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

      

Then run



composer update

      

on your terminal. Then try the migration script, it will solve your problem.

+1


source


Thanks to all posts

Solved with the following code:

 in config/database.php in mysql section


'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
 and replace them with with

'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',

      

0


source







All Articles