1 頁 (共 1 頁)

5.4 migrate users Error

發表於 : 2017-02-10 11:01:29
yehlu
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t
oo long; max key length is 767 bytes

https://laravel-news.com/laravel-5-4-key-too-long-error
https://news.laravel-china.org/posts/544

Laravel 5.4 把默认数据库字符集更改成 utf8mb4,作为对存储 emojis 的支持。只要你运行的是 MySQL v5.7.7 及更高版本,那么你就不会出现本文提到的错误。

对于那些运行 MariaDB 或旧版本的 MySQL 的程序,可能会在尝试运行迁移时遇到下面的错误:

[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
如 Laravel 5.4 中关于 迁移 的文档,你要做的是编辑 AppServiceProvider.php 文件,并在 boot 方法内设置默认字符串的长度:

代碼: 選擇全部

use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}
然后,就没然后了。

Stay Hungry, Stay Foolish.

参考链接:https://laravel-news.com/laravel-5-4-key-too-long-error

Re: 5.4 migrate users Error

發表於 : 2017-06-03 16:03:45
yehlu
yehlu@x4-640:/var/www/html/carstatus$ php artisan migrate
Migration table created successfully.


<?php


[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t
oo 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 t
oo long; max key length is 767 bytes

代碼: 選擇全部

vi app/Providers/AppServiceProvider.php