markdown Laravel:指定密钥错误太长

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Laravel:指定密钥错误太长相关的知识,希望对你有一定的参考价值。

Index Lengths & MySQL / MariaDB

Laravel uses the utf8mb4 character set by default, which includes support for storing "emojis" in the database. If you are running a version of MySQL older than the 5.7.7 release or MariaDB older than the 10.2.2 release, you may need to manually configure the default string length generated by migrations in order for MySQL to create indexes for them. You may configure this by calling the  Schema::defaultStringLength method within your AppServiceProvider

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

As outlined in the Migrations guide to fix this all you have to do is edit your AppServiceProvider.php file and inside the boot method set a default string length:

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

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

---
* posted by: Lâm Ngọc Khương
* site: https://ngockhuong.com
* email: me@ngockhuong.com
---

以上是关于markdown Laravel:指定密钥错误太长的主要内容,如果未能解决你的问题,请参考以下文章

Laravel 迁移错误:语法错误或访问冲突:1071 指定的键太长;最大密钥长度为 767 字节 laravel 5.3

laravel migration 指定的key太长;最大密钥长度为 767 字节 [重复]

laravel 错误 1071 密钥太长 php artisan migrate [重复]

为啥会出现此错误 #1071 - 指定的密钥太长;最大密钥长度为 1000 字节? [复制]

语法错误或访问冲突:1071 指定的密钥太长;最大密钥长度为 767 字节 [重复]

错误:#1071 - 指定的密钥太长;最大密钥长度为 1000 字节 - mysql 5.0.91