博客
关于我
laravel Specified key was too long 解决方案
阅读量:152 次
发布时间:2019-02-28

本文共 532 字,大约阅读时间需要 1 分钟。

在使用Laravel进行数据库迁移时,如果你遇到了索引长度相关的问题,可以按照以下步骤进行解决:

  • 检查数据库字符集:确保你的MySQL或MariaDB数据库已经配置了utf8mb4字符集。这是Laravel默认使用的字符集,支持存储emoji,并且可以处理较长的UTF-8编码。

  • 确认数据库版本:如果你的MySQL版本低于5.7.7或MariaDB低于10.2.2,可能需要手动调整默认字符串长度,以便迁移工具能够正确生成索引。

  • 配置默认字符串长度:在你的Laravel应用中,打开AppServiceProvider,找到boot方法。添加以下代码以设置默认的字符串长度:

    use Illuminate\Support\Facades\Schema;public function boot(){    Schema::defaultStringLength(191);}

    这一设置会告诉迁移工具在创建索引时使用长度为191的字符串,这是MySQL和MariaDB推荐的默认长度。

  • 执行迁移并测试:运行迁移命令,确保所有迁移操作顺利完成。检查迁移后的数据库,确认索引长度正确,并且没有产生错误。

  • 通过以上步骤,你可以解决索引长度问题,确保数据库迁移过程顺利进行。

    转载地址:http://lgbj.baihongyu.com/

    你可能感兴趣的文章
    npm报错Failed at the node-sass@4.14.1 postinstall script
    查看>>
    npm报错fatal: Could not read from remote repository
    查看>>
    npm报错File to import not found or unreadable: @/assets/styles/global.scss.
    查看>>
    npm报错unable to access ‘https://github.com/sohee-lee7/Squire.git/‘
    查看>>
    npm淘宝镜像过期npm ERR! request to https://registry.npm.taobao.org/vuex failed, reason: certificate has ex
    查看>>
    npm版本过高问题
    查看>>
    npm的“--force“和“--legacy-peer-deps“参数
    查看>>
    npm的安装和更新---npm工作笔记002
    查看>>
    npm的常用配置项---npm工作笔记004
    查看>>
    npm的问题:config global `--global`, `--local` are deprecated. Use `--location=global` instead 的解决办法
    查看>>
    npm编译报错You may need an additional loader to handle the result of these loaders
    查看>>
    npm设置淘宝镜像、升级等
    查看>>
    npm设置源地址,npm官方地址
    查看>>
    npm设置镜像如淘宝:http://npm.taobao.org/
    查看>>
    npm配置安装最新淘宝镜像,旧镜像会errror
    查看>>
    NPM酷库052:sax,按流解析XML
    查看>>
    npm错误 gyp错误 vs版本不对 msvs_version不兼容
    查看>>
    npm错误Error: Cannot find module ‘postcss-loader‘
    查看>>
    npm,yarn,cnpm 的区别
    查看>>
    NPOI
    查看>>