Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php artisan migrate fails Laravel [duplicate]

Tags:

php

laravel

I have the following error. Someone is understanding 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();
});
like image 981
ercvs Avatar asked Jul 08 '17 10:07

ercvs


3 Answers

you have to do is edit your AppServiceProvider.php on App\Providers\AppServiceProvider file and inside the boot method set a default string length:

use Illuminate\Support\Facades\Schema;

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

Then drop the database manually then composer dump-autoload and php artisan migrate

like image 121
Leo Avatar answered Oct 10 '22 01:10

Leo


Edit AppServiceProvider.php file, you will find this file in app/Providers/AppServiceProvider.php

use Illuminate\Support\Facades\Schema;

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

Then run

composer update

on your terminal. Then try migrating your script, It would solve your problem.

like image 1
S.M Talha Avatar answered Oct 10 '22 00:10

S.M Talha


Thanks all message

Resolved with next 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',
like image 1
ercvs Avatar answered Oct 10 '22 00:10

ercvs