Syntax error or access violation: 1071 Specified key was too long
When running database migration in a new larvel project, i get following error
boby@hon-pc-01:~/www/proxy (master)$ php artisan migrate
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 uniqueusers_email_unique
(In Connection.php line 458:
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
boby@hon-pc-01:~/www/proxy (master)$
This is due to recent change in Lavral, that changed default charset to utf8mb4.
To fix this error, open file
1 |
vi app/Providers/AppServiceProvider.php |
Find
1 |
use Illuminate\Support\ServiceProvider; |
Add below
1 |
use Illuminate\Support\Facades\Schema; |
Find
1 2 3 4 |
public function boot() { // } |
Replace with
1 2 3 4 |
public function boot() { Schema::defaultStringlength(191); } |