• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

【laravel5.4】phpartisanmigrate报错:Specifiedkeywastoolong;maxkeylengthis767byt ...

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1、原因:在进行 迁移文件生成时,程序并未给varchar类型字段设置 合适的长度,导致报错。

2、解决办法:找到database/ 目标迁移文件,修改其中类型为string的字段长度,建议不要超过255,否则报错 【然后再次运行php artisan migrate 即可成功】

 示例:

 

MySQL: ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes


今天测试遇到了这样的问题:

 

MySQL>  use test; create table test(a varchar(512) primary key, b varchar(1024));
Database changed
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes

 

相关测试:

http://kklinux.com/bbs/archiver/tid-2543.html

 

drop table if exists test; 
create table test(test varchar(767) primary key)charset=latin5; 
-- 成功 

drop table if exists test; 
create table test(test varchar(768) primary key)charset=latin5; 
-- 错误  
-- ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes 

drop table if exists test; 
create table test(test varchar(383) primary key)charset=GBK; 
-- 成功 

drop table if exists test; 
create table test(test varchar(384) primary key)charset=GBK; 
-- 错误  
-- ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes 

drop table if exists test; 
create table test(test varchar(255) primary key)charset=UTF8; 
-- 成功 

drop table if exists test; 
create table test(test varchar(256) primary key)charset=UTF8; 
-- 错误  
-- ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes

 

原因:

MySQL的varchar主键只支持不超过768个字节 或者 768/2=384个双字节 或者 768/3=256个三字节的字段 
而 GBK是双字节的,UTF-8是三字节的。

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
php使用Iframe无刷新上传发布时间:2022-07-10
下一篇:
php文件上传,下载发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap