When you perform a data migration in laravel5.5
PHP Artisan Migrate
First, the system environment:
Ubutun Ubuntu 16.04.3 LTS
Mysql:5.6.35-log
The character encoding is used by default since Laravel 5.4 utf8mb4
, not the previous utf8
encoding. As a result, the php artisan migrate
above error will occur.
Source of the problem
MySQL supports encoding with a utf8
maximum character length of 3 bytes, and an insert exception occurs if a wide character of 4 bytes is encountered. Three bytes UTF-8 the maximum encoding Unicode character is 0xFFFF, which is the basic Multilingual Plane (BMP) in Unicode. Thus, the Unicode characters of non-basic multilingual planes, including emoji emoticons (emoji is a special Unicode encoding), cannot be stored using the MySQL utf8
character set.
This should also be one of the reasons why Laravel 5.4 used 4-byte-length utf8mb4
character encoding instead. It is important to note, however, that only MySQL 5.5.3 version will begin to support utf8mb4
character encoding (view version: selection version();
). If the MySQL version is too low, a version update is required.
Note: If you are upgrading from Laravel 5.3 to Laravel 5.4, you do not need to switch the character encoding.
Solve the problem
Upgrade MySQL version to 5.5.3 or more.
Laravel default 1071, and the error indicates that the database set the maximum is 767, so the error
Laravel 5.4 uses utf8mb4
the character encoding by default instead of the previous utf8
encoding. The maximum character length for Mb4 is 4 bytes, and the workaround is:
Manually configure the migration command migrate the resulting default string length, calling Schema in Appserviceprovider::d the Efaultstringlength method to implement the configuration:
Perform:p hp artisan migrate again
It seems that the mistake is different. After looking for MySQL to perform a security mode check, Laravel's config/database.php mysql option configured strict mode by default to True, modified to:
After executing again:
Ok.. Complete..
laravel5.5 Syntax Error or Access violation:1071 Specified key was too long