Error Code: 1071. Specified key was too long;

錯誤信息mysql

Error Code: 1071. Specified key was too long; max key length is 767 bytessql

表結構 ide

CREATE TABLE yundou_data_system.`object_event` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `object_id` int(11) unsigned NOT NULL DEFAULT '0',
  `event_name` varchar(256) NOT NULL DEFAULT '',
  `create_time` int(11) unsigned NOT NULL DEFAULT '0',
  `status` tinyint(1) unsigned NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`),
  UNIQUE KEY `unq_event_name` (`event_name`),
  KEY `idx_object_id` (`object_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='對象事件表'

緣由
mysql的varchar主鍵只支持不超過767個字節或者768/2=384個雙字節 或者767/3=255個三字節的字段 而GBK是雙字節的,UTF8是三字節的。code

解決方案對象

`event_name` varchar(255) NOT NULL DEFAULT '',
相關文章
相關標籤/搜索