markdown SQLSTATE [42000]:迁移命令时指定的键太长错误

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown SQLSTATE [42000]:迁移命令时指定的键太长错误相关的知识,希望对你有一定的参考价值。

## Error
> [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 

## Solution
* Update to newerst MySQL version
* Change charaset from utf8mb4
* Change the maximum value of the column so that the character string of 767 bytes or more is not included

```
$ find / -name AppServiceProvider.php
$ vim app/Providers/AppServiceProvider.php
```

```
use Illuminate\Support\Facades\Schema;

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


## Reference link

[Laravel 5.4: Specified key was too long error](https://laravel-news.com/laravel-5-4-key-too-long-error)

以上是关于markdown SQLSTATE [42000]:迁移命令时指定的键太长错误的主要内容,如果未能解决你的问题,请参考以下文章

照亮\数据库\查询异常 SQLSTATE [42000]

我该如何解决这个错误,SQLSTATE [42000]? [复制]

Illuminate\Database\QueryException:SQLSTATE[42000]:语法错误或访问冲突:1064

未捕获的 PDOException:SQLSTATE[42000]:语法错误或访问冲突

带有消息“SQLSTATE [42000]”的未捕获异常“PDOException”:语法错误或访问冲突:

“SQLSTATE [42000] [1044] 拒绝用户 'team'@'localhost' 访问数据库 'my database''