多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > 數據庫 > MySql > mysql提示used in key specification without a key length

mysql提示used in key specification without a key length

來源:程序員人生   發布時間:2014-03-03 05:24:20 閱讀次數:6514次

今天最火軟件站小編在寫一個PHP小東西的時候遇到了一個問題,設計數據庫類型的時候提示:xxxx used in key specification without a key length,百思不得其解,后來在網上找到關于這個問題的答案。

原來Mysql數據庫對于BLOB/TEXT這樣類型的數據結構只能索引前N個字符。所以這樣的數據類型不能作為主鍵,也不能是UNIQUE的。所以要換成VARCH,但是VARCHAR類型的大小也不能大于255,當VARCHAR類型的字段大小如果大于255的時候也會轉換成小的TEXT來處理。所以也同樣有問題。

官方的英文解釋如下:

  1. The error happens because MySQL can index only the first N chars of a BLOB or TEXT column. So The error mainly happen when there is a field/column type of TEXT or BLOB or those belongs to TEXT or BLOB types such as TINYBLOB, MEDIUMBLOB, LONGBLOB, TINYTEXT, MEDIUMTEXT, and LONGTEXT that you try to make as primary key or index. With full BLOB or TEXT without the length value, MySQL is unable to guarantee the uniqueness of the column as it’s of variable and dynamic size. So, when using BLOB or TEXT types as index, the value of N must be supplied so that MySQL can determine the key length. However, MySQL doesn’t support a key length limit on TEXT or BLOB. TEXT(88) simply won’t work.  
  2. The error will also pop up when you try to convert a table column from non-TEXT and non-BLOB type such as VARCHAR and ENUM into TEXT or BLOB type, with the column already been defined as unique constraints or index. The Alter Table SQL command will fail.  
  3. The solution to the problem is to remove the TEXT or BLOB column from the index or unique constraint, or set another field as primary key. If you can’t do that, and wanting to place a limit on the TEXT or BLOB column, try to use VARCHAR type and place a limit of length on it. By default, VARCHAR is limited to a maximum of 255 characters and its limit must be specified implicitly within a bracket right after its declaration, i.e VARCHAR(200) will limit it to 200 characters long only.  
  4. Sometimes, even though you don’t use TEXT or BLOB related type in your table, the Error 1170 may also appear. It happens in situation such as when you specify VARCHAR column as primary key, but wrongly set its length or characters size. VARCHAR can only accepts up to 256 characters, so anything such as VARCHAR(512) will force MySQL to auto-convert the VARCHAR(512) to a SMALLTEXT datatype, which subsequently fail with error 1170 on key length if the column is used as primary key or unique or non-

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 久久成人小视频 | 亚洲欧美日韩第一页 | 欧美日本一区 | 2015日韩永久免费视频播放 | 亚洲精品第一 | 欧美精品久久久久久久影视 | 国产精品久久久久久久免费大片 | 日韩福利在线视频 | 羞羞免费网站 | 成人免费一区二区三区在线观看 | 国产欧美一区二区成人影院 | 精品成人免费自拍视频 | 最近手机中文字幕高清1 | 99一级毛片 | 校园春色偷拍自拍 | 欧美大片毛片aaa免费看 | 波多野结衣一区在线观看 | 亚洲成人国产精品 | 欧美日韩中文字幕 | 中文字幕视频一区二区 | 欧美国产第一页 | 欧美成人精品不卡视频在线观看 | 久久91久久91精品免费观看 | 精品伊人| a久久久久一级毛片护士免费 | 欧美孕交videofree巨大 | 在线观看亚洲一区 | 欧美精品v国产精品v | 999yy成年在线视频免费看 | 在线观看免费a∨网站 | 欧美日韩一区二区三区视频在线观看 | 日韩欧美在线观看视频 | 国产美女久久久久久久久久久 | 亚洲成人一级 | 亚洲综合一二三区 | 国产成人精品日本亚洲语言 | 在线精品小视频 | 国产成人高清 | 在线观看麻豆国产精品 | 69视频在线免费观看 | 中文天堂最新版在线精品 |