MySQL Error 1170 (42000): BLOB/TEXT Column Used in Key Specification Without a Key Length MySQL的錯誤1170 ( 42000 ) : BLOB的/文本列中使用的主要規格,沒有一個密鑰長度
When creating a new table or altering an existing table with primary keys, unique constraints and indexes, or when defining a new index with Alter Table manipulation statement in MySQL database, the following error may occur and prohibit the the command from completing:當創建一個新表或改變現有的資料表與主鍵,獨特的制約因素和指標,或當確定一個新的指數與改變表操縱的聲明在MySQL數據庫,下面的錯誤,可能會出現和禁止命令完成:
ERROR 1170 (42000): BLOB/TEXT column ‘field_name’ used in key specification without a key length錯誤1170 ( 42000 ) : BLOB的/純文字欄' field_name '用在關鍵的規格沒有一個密鑰長度
The error happens because MySQL can index only the first N chars of a BLOB or TEXT column.錯誤發生,因為MySQL的,可以編制索引,只有前n字一個的BLOB或文本列。 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.因此錯誤主要發生時,有一個外地/列類型的文字或BLOB的或那些屬於文字或BLOB的類型,如tinyblob , mediumblob , longblob , tinytext , mediumtext , longtext您嘗試,使作為主鍵或索引。 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.與充分的BLOB或文字沒有長度值, MySQL的,是無法保證的唯一一欄,因為它的可變和動態的大小。 So, when using BLOB or TEXT types as index, the value of N must be supplied so that MySQL can determine the key length.所以,當使用的BLOB或TEXT類型作為指數,價值的N必須提供使MySQL的可確定密鑰長度。 However, MySQL doesn’t support limit on TEXT or BLOB.然而, MySQL的不支持限制的文字或BLOB的。 TEXT(88) simply won’t work.文字( 88 )是行不通的。
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.錯誤也將彈出當您嘗試轉換表列從非文字和非BLOB的類型,如varchar和的ENUM到文本或BLOB的類型,與列已經被定義為獨特的限制,或指數。 The Alter Table SQL command will fail.該改變表SQL命令就會失敗。
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.問題的解決方法是刪除文字或BLOB的列從索引或唯一約束,或設置的另一個領域作為主鍵。 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.如果你不能做到這一點,並要設立一個限制,對文本的BLOB或專欄,嘗試使用varchar類型和地點的限制長度對。 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, ie VARCHAR(200) will limit it to 200 characters long only.默認情況下, varchar是限於最多255個字符及其限度必須指定含蓄地在一個支架後,其權利宣言,即varchar ( 200 )會限制它有200個字元,長期只。
Sometimes, even though you don’t use TEXT or BLOB related type in your table, the Error 1170 may also appear.有時,即使您不使用文字或BLOB的相關輸入您的表,誤差1170年,也可能出現。 It happens in situation such as when you specify VARCHAR column as primary key, but wrongly set its length or characters size.它發生的情況,例如當您指定varchar列作為主鍵,但錯誤設置它的長度或字符的大小。 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-unique index. varchar只能接受多達256個字符,因此任何如varchar ( 512 ) ,將迫使MySQL的自動轉換為varchar ( 512 )一smalltext數據,隨後失敗與錯誤, 1170年對密鑰長度,如果欄是用來作為小學關鍵或獨特性或非唯一索引。 To solve this problem, specify a figure less than 256 as the size for VARCHAR field.要解決這個問題,指定一個數字少於256作為大小為varchar領域。
IMPORTANT : This is a machine translated page which is provided "as is" without warranty. 重要說明 :這是一個機器翻譯網頁是“按原樣”提供的擔保。 Machine translation may be difficult to understand.機器翻譯可能很難理解。 Please refer to請參閱 original English article原來的英語文章 whenever possible.只要有可能。
Share and contribute or get technical support and help at分享和貢獻,或取得技術的支持和幫助,在 My Digital Life Forums 我的數字生活論壇 . 。
Related Articles相關文章
- How to Convert Character Set and Collation of WordPress Database如何轉換字符集和校對WordPress的數據庫
- Create New Table by Selecting Data from Other Tables with CREATE TABLE AS創造新的表中選擇數據從其他表與創建表作為
- Installing Web Server in FreeBSD 6.0 with Apache 2.2, MySQL 5.0 and PHP 5 - Part 3安裝Web服務器在FreeBSD的6.0與2.2的Apache , MySQL 5.0的和PHP 5 -第3部分
- Install Web Server in Windows XP with Apache2, PHP5 and MySQL4 - Part 4安裝Web服務器在Windows XP的Apache2 , php5和mysql4 -第4部分
- Change and Reset MySQL root Password改變和重置MySQL的root密碼
- ORA-02449 Oracle Drop Table Error庫存- 02449甲骨文下拉表錯誤
- Enable MySQL InnoDB Storage Engine Support in XAMPP Installation使MySQL的InnoDB存儲引擎支持在xampp安裝
- Easily Duplicate, Copy or Backup Tables in Oracle, PostgreSQL, DB2 and SQLite with Create Table As SQL很容易複製,拷貝或備份表在Oracle和PostgreSQL , DB2和sqlite與創建表的SQL
- WordPress MySQL SQL Query Error in WPDB Class在WordPress MySQL的SQL查詢錯誤在wpdb級
- Oracle PL/SQL ORA-00947 Not Enough Values Error甲骨文PL / SQL的庫存- 00947沒有足夠的價值觀錯誤




























August 30th, 2007 18:33 2007年8月30日18時33分
Thanks for putting this up.感謝這個了。 I didn’t get the error and you saved me a lot o frustration.我沒有錯誤,你救了我很多o挫折感。 I’d put you in the ‘Goog people’ category anytime我要你在' goog人'類別隨時
February 20th, 2008 02:45 2008年2月20日2時45分
Thanks!謝謝! Very useful post.非常有用的職位。
February 23rd, 2008 03:40 2008年2月23日3時40分
Thanks for the post.感謝該職位。 Very helpful.非常有幫助。
March 7th, 2008 04:15 2008年3月7日4時15分
Thanks, very good defined感謝,很好的界定