Reputation: 95
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `translations` add unique `translations_table_name_co
lumn_name_foreign_key_locale_unique`(`table_name`, `column_name`, `foreign_key`, `locale`))
I add this
use Illuminate\Support\Facades\Schema;
Schema::defaultStringLength(191);
But nothing change , still getting this error
Upvotes: 3
Views: 11506
Reputation: 561
You can see 3 solution here https://youtu.be/EWZfHyNs08c or follow these
Solution 1:
Changing default engine to InnoDB
from phpmyadmin did the trick for me.
I am using Windows + WAMP + Laravel 8, I updated
app/Providers/AppServiceProvider.php
with
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
but still it was not working. I figured out that tables were being created with default engine MyISAM
. I dropped the database (I was just setting up so I could afford to drop the database) and changed default engine to InnoDB
from Variables > storage engine.
I run php artisan migrate
again and it worked.
Solution 2:
As Javier Pérez Batista answered here.
Both worked for me, I tried both ways.
Upvotes: 3
Reputation: 398
You also need to update the config/database.php
file for mysql
connections from 'engine' => null,
to 'engine' => 'InnoDB ',
config/database.php
use Illuminate\Support\Str;
return [
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'mysql' => [
...
'engine' => 'InnoDB',
...
]
]
]
Be sure to set the service provider correctly (I assume you are already doing it base on your shared code)
app/Providers/AppServiceProvider.php
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
And remember to clear cache and configuration
php artisan cache:clear
php artisan config:clear
For more info on this issue: https://github.com/the-control-group/voyager/issues/901
Upvotes: 18