【问题标题】:laravel default username & password migration errorlaravel 默认用户名和密码迁移错误
【发布时间】:2018-07-10 07:55:15
【问题描述】:

在 Connection.php 第 647 行:

SQLSTATE[42000]:语法错误或访问冲突:1071 指定的键是 太长;最大密钥长度为 1000 字节(SQL:alter table users add uni 阙users_email_unique(email))

在 Connection.php 第 449 行:

SQLSTATE[42000]:语法错误或访问冲突:1071 指定的键是 太长;最大密钥长度为 1000 字节。 . . .

我该如何解决这个问题??

当我想在 CMD 中迁移默认迁移时,会发生此错误。

【问题讨论】:

  • 设置更短的密钥长度?您已将电子邮件字段设置为非常长的值?能发一下表结构吗?
  • 嗯,这是因为 mySQL 索引仅适用于长度小于 192 的字符串。您可能需要更改 defaultStringLength ..

标签: php laravel


【解决方案1】:

将此添加到您的 AppServiceProvider.php 文件中:

public function boot()
{
    Schema::defaultStringLength(191);
}

Laravel Newsarticle 解释了它

【讨论】:

    【解决方案2】:

    对于 Laravel 5.4,在 AppServiceProvider.php 中添加代码

    use Illuminate\Support\Facades\Schema;
    

    boot

    public function boot()
    {
        Schema::defaultStringLength(191);
    }
    

    【讨论】:

      猜你喜欢
      • 2020-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-18
      • 2016-10-06
      • 1970-01-01
      • 2013-06-03
      • 2016-12-19
      相关资源
      最近更新 更多