Trying to migrate in Laravel. When run “$ php artisan migrate” get this error :
[Illuminate\Database\QueryException] SQLSTATE: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
Doctrine\DBAL\Driver\PDOException::("SQLSTATE: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
PDOException::("SQLSTATE: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes")
Ok, solution I got it from stackoverflow.com (This Link)
As of Laravel 5.4 those changes are no more needed.
Laravel 5.4 uses the utf8mb4 character set by default, which includes support for storing "emojis" in the database. If you are upgrading your application from Laravel 5.3, you are not required to switch to this character set.
Current production MariaDB versions DO NOT support this setting by default globally. It is implemented in MariaDB 10.2.2+ by default.
And if you intentionally want to use the correct future-default (starting from Laravel 5.4) UTF8 multi-byte
utf8mb4 support for 😀 then start to fix 😂 your database configuration.
'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',
DYNAMIC allows to store long key indexes.
Server settings (by default included in MySQL 5.7.7+ / MariaDB 10.2.2+):
[mysqld] # default character set and collation collation-server = utf8mb4_unicode_ci character-set-server = utf8mb4 # utf8mb4 long key index innodb_large_prefix = 1 innodb_file_format = barracuda innodb_file_format_max = barracuda innodb_file_per_table = 1
And then STOP your MySQL/MariaDB server. After that START. Hot RESTART may not work.
sudo systemctl stop mysqld sudo systemctl start mysqld
Now you have Laravel 5.x with UTF8 support.
NB : just copy from stackoverflow.com (This Link).