Dragon
主机之家测评主机之家测评  2019-08-27 18:11 主机之家测评 隐藏边栏 |   抢沙发  94 
文章评分 0 次,平均分 0.0

laravel 5.4 版本改变默认的数据库字符集为 utf8mb4。如果你运行 MySQL v5.7.7 或者更高版本,则不需要做任何事情。

否则你在运行 migrations 命令时,可能会碰到下面这个错误:

  [IlluminateDatabaseQueryException]  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))  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes  
  我们可以在 appProvidersAppServiceProvider.php 文件里中的 boot 方法里设置一个默认值来解决这个错误:
  Schema::defaultStringLength(200);

完整的 AppServerProvider.php 文件代码如下:

  <?php  namespace AppProviders;    use IlluminateSupportServiceProvider;  use IlluminateSupportFacadesSchema;    class AppServiceProvider extends ServiceProvider  {      public function boot()      {          Schema::defaultStringLength(200);      }        public function register()      {          //      }  }  

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

发表评论

扫一扫二维码分享