laravel 运行migrate报错 1071 Specified key was too long

laravel运行命令migrate时报错:

1071 Specified key was too long; max key length is 1000 bytes (S

  QL: 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 1000 bytes

     解决:

  1. 升级MySql版本到5.5.3以上。

  2. 手动配置迁移命令migrate生成的默认字符串长度,App/Providers/AppServiceProvider.php

    <?php

    namespace AppProviders;

    use IlluminateSupportServiceProvider;
    use IlluminateSupportFacadesSchema;

    class AppServiceProvider extends ServiceProvider
    {
    /**
    * Bootstrap any application services.
    *
    * @return void
    */
    public function boot()
    {
    Schema::defaultStringLength(191);
    }
记录点滴,迭代精进,追求新生。Email: 942298768@qq.com
原文地址:https://www.cnblogs.com/chaoyong/p/8990503.html