PHP

首页 -  PHP  -  Laravel数据库迁移错误

Laravel数据库迁移错误

 Laravel在迁移数据库的时候抛出异常Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes 

原因:utf8 => utf8mb4), 从而使 email 字段索引长度超过了的默认限制长度.
而新版本 mysql>= 5.7.7 默认打开了 innodb_large_prefix , 使索引长度限制由 767bytes 增加到了 3072bytes. 所以不会导致迁移报错.

解决方案1:修改Laravel配置文件

namespace App\Providers;
// 导入Schema类
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        // 在app/providers/AppServiceProvider.php中boot方法中加上
        Schema::defaultStringLength(191);
    }
}

解决方案2:修改mysql配置

查看配置文件是不是为开启
show variables like 'innodb_large_prefix'
如果是OFF那就需要去设置
set global innodb_large_prefix=ON
查看如果不是Barracuda
show variables like 'innodb_file_format' 
设置
set global  innodb_file_format=Barracudazh

注意这个设置只对innodb生效

如果你修给了以上配置那还是不可以的话就去查看一下mysql的存储引擎是不是默认为Innodb如果不是修改下默认的存储引擎就可以了

修改my.ini文件如果是linux就是my.cnf
default-storage-engine=INNODB
(0)
分享:

本文由:xiaoshu168 作者:xiaoshu发表,转载请注明来源!

相关阅读