【laravel5.4】php artisan migrate报错:Specified key was too long; max key length is 767 bytes

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是三字节的。
【laravel5.4】php artisan migrate报错:Specified key was too long; max key length is 767 bytes的更多相关文章
- PHP artisan migrate 报错显示 could not find driver ,怎么办?
记录下自己的错误 一. 1.原因是没有pdo扩展导致的, 2.解决办法:打开php.ini,然后去掉以下两行代码之前的分号(:)即可.如下: extension=php_pdo_firebird.dl ...
- php artisan 命令报错,什么命令都是这个错误,cmd下运行也不行,又没看到语法错误
Laravel 5.1 以上的版本的框架需求PHP的版本是5.5以上的版本.如果你的PHP版本等级太低,将会出现上述的问题. 估计你要升级你的PHP版本了.
- django migrate报错(提前删除表等)
python3 manage.py makemigrations python3 manage.py migrate ##报错 改为##更改migrates的状态 python3 manage.py ...
- Python Django migrate 报错解决办法
1. 在现有基础上又添加一个表的时候migrate报错 migrate报错django.db.utils.OperationalError: (1050, "Table 'cmdb_eidc ...
- Lavarel 执行:php artisan migrate时报错
错误如下: 执行:php artisan migrate时报错: [PDOException]SQLSTATE[HY000] [2002] Connection refused 解决办法: 第一步:. ...
- Django(21)migrate报错的解决方案
前言 在讲解如何解决migrate报错原因前,我们先要了解migrate做了什么事情,migrate:将新生成的迁移脚本.映射到数据库中.创建新的表或者修改表的结构. 问题1:migrate怎么判断哪 ...
- laravel 运行migrate报错 1071 Specified key was too long
转自:https://segmentfault.com/a/1190000008416200 laravel运行命令migrate时报错: 1071 Specified key was too lo ...
- laravel migrate时报错:Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
今天在学习laravel的路由模型绑定时,在按照文档执行php artisan migrate时报错. In Connection.php line 664: SQLSTATE[42000]: Syn ...
- 导入sql文件报错:1071 Specified key was too long; max key length is 767 bytes
ref: https://stackoverflow.com/questions/1814532/1071-specified-key-was-too-long-max-key-length-is-7 ...
随机推荐
- ConcurrentDictionary AddOrUpdate
var sessionId = a.Session.SessionID.ToString(); userDic.AddOrUpdate( authUser.UserId, sessionId, (ke ...
- C#,数据类型扩展 z
MACD的公式 DIFF : EMA(CLOSE,SHORT) - EMA(CLOSE,LONG);DEA : EMA(DIFF,M); MACD : 2*(DIFF-DEA), COLORSTIC ...
- Oracle存储过程update受外键约束的主键值时完整性冲突解决方式
1.问题背景 尽管在数据库操作中我们并不提倡改动主键,可是确实在实际生活中有这种业务需求: 表A有主键KA,表B中声明了一个references A(KA)的外键约束.我们须要改动A中某条目KA的值而 ...
- pytest文档24-fixture的作用范围(scope)
fixture作用范围 fixture里面有个scope参数可以控制fixture的作用范围:session > module > class > function fixture( ...
- git 查看commit提交的内容
在使用git的过程中,我们经常需要查看某次commit修改了哪些内容,与之相关的命令就是: git log git show 首先,需要通过git log打印所有commit hashID,之后的gi ...
- NLP十大里程碑
NLP十大里程碑 2.1 里程碑一:1985复杂特征集 复杂特征集(complex feature set)又叫做多重属性(multiple features)描写.语言学里,这种描写方法最早出现在语 ...
- HttpMessageConverter
HttpMessageConverter<T>是Spring3的一个重要接口,它负责将请求信息转换为一个对象(类型为T),将对象(类型为T)输出为响应信息. DispatcherServl ...
- [每日一题] OCP1z0-047 :2013-08-04 INSERT --- WITH CHECK OPTION
这题是考:insertWITH CHECK OPTION的用法 insert into (<select clause> WITH CHECKOPTION) values (...) 这样 ...
- Cesium随笔(3)随鼠标实时显示经纬度坐标以及高度【转】
在网页三维地球上进行可视化开发与经纬度坐标以及高度是分不开的,能够实时获取鼠标位置的经纬度对可视化效果有很好的帮助,Cesium当然能做到: (1)首先在里创建显示坐标的容器 样式自己调整的合适即可 ...
- Binary Tree Preorder Traversal leetcode java
题目: Given a binary tree, return the preorder traversal of its nodes' values. For example: Given bina ...