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感谢,很好的界定