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 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);
    }
上一篇:Mongo运行错误:Failed to connect 127.0.0.1:27017,reason:errno:10061由于目标计算机积极拒绝,无法连接


下一篇:1.MongoDB报错 Failed to connect 127.0.0.1:27017 Mongo运行错误