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:
- Laravel-admin php artisan admin:install error reporting problem solution
- [Solved] PDOException::(“SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long;
- Laravel5.5 Error: SQLSTATE[42000] Syntax error or access violation 1071 Specified key was too long; max k
- [PHP]json_encode Chinese JSON_UNESCAPED_UNICODE returns null in php5.3
- Unserialize(): cause analysis and solution of error at offset
- [Solved] WordPress Upgrade PHP 5.6 to 7.x Fatal error: Uncaught Error: Call to undefined function mysql_connect()
- Undefined index: name error in composer [How to Solve]
- PHP error in Windows: class’ mysqli ‘not found
- 404 solution for WordPress Chinese tag
- Tp6 Cannot enable error [How to Solve]
- PHP solves the problem that composer exceeds the memory size Allowed memory size
- [Solved] ‘node’ command failed to start the project, with an error: “unknown database’ mydb ‘”
- [Solved] PhpSpreadsheet Error: Invalid cell coordinate [1
- [Solved] Error while sending STMT_PREPARE packet. PID=29294
- [Solved] PHP post Datas json_decode Error: 4 JSON_ERROR_SYNTAX
- [PHP] php8 jit does not support 32-bit systems WARNING: JIT not supported by host architecture
- PHP: How to parse MHT file into HTML
- Configure: error: Cannot find libz error appears when brew installs php70
- How to solve Magento 500 internal server errors
- Mac PHP Fatal error: Class ‘Memcache’ not found