Problem Description:
php artisan migrate Error:
Illuminate\Database\QueryException
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `users` add unique `users_em
ail_unique`(`email`))
Cause Analysis:
The maximum character length of utf8 encoding supported by MySql is 3 bytes, if a wide character of 4 bytes is encountered, an insertion exception will occur. The maximum Unicode character that can be encoded by three bytes UTF-8 is 0xffff, which is the basic multiliterate plane (BMP) in Unicode. Therefore, Unicode characters that are not in the Basic Multicultural Plane, including Emoji emojis (Emoji is a special Unicode encoding), cannot be stored using MySql’s utf8 character set.
This should also be one of the reasons why Laravel 5.4 switched to the 4-byte length utf8mb4 character encoding. However, it should be noted that the utf8mb4 character encoding is only supported from MySql version 5.5.3 onwards (check the version: selection version();). If the MySql version is too low, a version update is required.
Solution:
1. Upgrade MySql version to 5.5.3 or higher. Add in /app/providers/AppServiceProvider.php:
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
2. Delete the table in the database and re execute php artisan migrate
Read More:
- Laravel5.5 Error: SQLSTATE[42000] Syntax error or access violation 1071 Specified key was too long; max k
- [Solved] PDOException::(“SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long;
- Laravel-admin php artisan admin:install error reporting problem solution
- Syntax error: typeerror: about installing sass in vue3 this.getOptions is not a function
- composer Error: The requested PHP extension ext-bcmath * is missing from your system. Install or enable
- [Solved] OpenSSL Error messages: error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure
- [PHP] Solve the limitation of uploading files in nginx php 413 Request Entity Too Large
- PHP large file upload error 413: request entity too large [How to Solve]
- [Solved] PHP post Datas json_decode Error: 4 JSON_ERROR_SYNTAX
- [Solved] has been blocked by CORS policy: Response to preflight request doesn‘t pass access control check: No
- PHP parse error: syntax error, unexpected ‘use’
- [Solved] Laravel admin Error: Symfony\Component\Debug\Exception\FatalThrowableError : Class ‘Doctrine\DBAL\Driver\PDOMySql\Driver’ not found
- Error while injecting dependencies into App\Controller\IndexController: No entry or class found for
- /www/server/php/56/sbin/php-fpm:error while loading shared libraries:libssl.so.1.0. 0:cannot open shared object file:No such file or directory
- Error during session start; please check your PHP and/or webserver log file and configure your PHP
- Undefined index: name error in composer [How to Solve]
- PHP php-config is not installed error in ubuntu 16 [How to Solve]
- Mac installs the php Swoole extension and appears Enable openssl support, require openssl library or fatal error:’openssl/ssl.h’ file not found
- [PHP]json_encode Chinese JSON_UNESCAPED_UNICODE returns null in php5.3
- Mac: Where is php.ini Location