Reputation: 543
when I run migrate command with laravel 5.4 I get an error "specific key was too long", I searched and found many people also face this error. The common is add Schema::defaultStringLength(191);
in AppServiceProvider.php
. But the doc https://laravel-news.com/laravel-5-4-key-too-long-error says it is for those mysql version older than 5.7.7. But my version is 5.7.14(mysql Ver 14.14 Distrib 5.7.14, for Win64 (x86_64)
), and I already set mysql default charset to utf8mb4(show variables like "%char%"
):
So I think I do not need to change anything but I still get the problem. It makes me confused. Who can help me? Thanks.
Upvotes: 0
Views: 1098
Reputation: 11
go to config/database.php set this 'engine'=>innodb.
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => innodb,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
Upvotes: 0
Reputation: 19781
innodb_file_format=Barracuda
innodb_large_prefix=1
innodb_default_row_format=dynamic
Step 1 (innodb_file_format) and 2 (innodb_large_prefix) works on older Mysql versions, including MariaDB. I do not know the lower version bounds for these. Mysql 5.7.7 changed the defaults for these settings, but they existed earlier.
Step 3 (innodb_default_row_format) requires Mysql 5.7.9 or newer.
For the sake of documentation; a workaround if you're missing the innodb_default_row_format setting is to use the engine innodb row_format=dynamic
. This abuses the fact that Laravel appends this to the CREATE TABLE statement without any escaping, resulting in ... ENGINE=innodb row_format=dynamic
.
Laravel 5.2.14 introduced the ability to specify the engine in config/database.php
. If you're on an older version you have to specify this in every migration that creates a table. $table->engine = 'innodb row_format=dynamic';
Upvotes: 1
Reputation: 111829
I think you should make sure you have set innodb_large_prefix
to On
. According to documentation it should be default in Mysql >= 5.7.7 but maybe you use non-standard settings.
Upvotes: 0