laravel 5.4 改变了默认的数据库字符集,如今utf8mb4包括存储emojis支持。若是你运行MySQL v5.7.7或者更高版本,则不须要作任何事情。php
当你试着在一些MariaDB或者一些老版本的的MySQL上运行 migrations 命令时,你可能会碰到下面这个错误:laravel
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table users add unique users_email_unique(email))
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
咱们能够在 AppServiceProvider.php 文件里的 boot 方法里设置一个默认值:数据库
<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\Schema; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */
public function boot() { Schema::defaultStringLength(191); } /** * Register any application services. * * @return void */
public function register() { // } }
原谅地址:https://laravel.com/docs/master/migrations#creating-indexesapp
******ide