Results 1 to 5 of 5

Thread: MySQL Error: BLOB/TEXT Column Used in Key Specification

  1. #1
    Join Date
    Feb 2009
    Posts
    48

    MySQL Error: BLOB/TEXT Column Used in Key Specification

    In MySQL database, when creating a new table or altering an existing table with primary keys, unique constraints and indexes, I receive the following error message -

    "ERROR 1170 (42000): BLOB/TEXT column ‘field_name’ used in key specification without a key length"

    Any ideas....

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: MySQL Error: BLOB/TEXT Column Used in Key Specification

    The above error occurs because MySQL is able to index only the first N chars of a BLOB or TEXT column. Hence, this occurs when there is a field/column type of TEXT or BLOB or those belonging to TEXT or BLOB types such as TINYBLOB, MEDIUMBLOB, LONGBLOB, TINYTEXT, MEDIUMTEXT, and LONGTEXT that you try to make as primary key or index.

    however, MySQL is unable to guarantee the uniqueness of the column as it’s of variable and dynamic size with full BLOB or TEXT without the length value. So, when using BLOB or TEXT types as index, the value of N must be supplied so that MySQL can determine the key length.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: MySQL Error: BLOB/TEXT Column Used in Key Specification

    In MySQL, you need to give a key size ( 256 and above ) to the columns of TEXT and BLOB type.

    > ALTER TABLE mytable ADD INDEX mytable_username_index (username(256));

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: MySQL Error: BLOB/TEXT Column Used in Key Specification

    To solve this problem,
    remove the TEXT or BLOB column from the index or unique constraint, or set another field as primary key.

    If you want to place a limit on the TEXT or BLOB column, try to use VARCHAR type and place a limit of length on it.
    Note - VARCHAR is limited to a maximum of 255 characters by default, but you can specify its limit within a bracket right after its declaration for e.g. VARCHAR(200) - This will limit it to 200 characters long only.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: MySQL Error: BLOB/TEXT Column Used in Key Specification

    The error may also occur while defining a new index with Alter Table manipulation statement. 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.

Similar Threads

  1. Mysql error message "Unknown column in on clause"
    By Carnie in forum Software Development
    Replies: 3
    Last Post: 21-11-2009, 11:03 AM
  2. Replies: 3
    Last Post: 07-11-2009, 09:36 PM
  3. Column Formatting for Text Box in Microsoft Publisher
    By gmatting in forum Windows Software
    Replies: 1
    Last Post: 07-09-2009, 09:19 AM
  4. How to count number of text occurences in Excel column
    By Anas in forum Windows Software
    Replies: 3
    Last Post: 09-06-2009, 05:01 PM
  5. mysql update column with another column
    By Gunter in forum Software Development
    Replies: 3
    Last Post: 23-05-2009, 09:44 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,955,969.48940 seconds with 16 queries