DBAtlas · Database operations atlas

1170: ER_BLOB_KEY_WITHOUT_LENGTH: BLOB/TEXT column used in key specification without a key length

MySQL

What does it mean?

You used a BLOB or TEXT column in an index/key definition without specifying a prefix length. These types cannot be indexed in full; only the first N characters/bytes can be indexed.

Why does it happen?

Defining an INDEX/UNIQUE/PRIMARY KEY on a TEXT/BLOB column without a length in CREATE TABLE or CREATE INDEX. MySQL requires a prefix length because it cannot index these potentially very large values in full.

How to fix it

Specify a prefix length in the index, such as INDEX (description(255)). Example: ALTER TABLE my_table ADD INDEX idx_description (description(191)); (191 is commonly used with utf8mb4 because of the InnoDB key prefix limit). If full-text search is needed, consider a FULLTEXT index. For fields that should be short and unique, converting the column to VARCHAR may be more appropriate.

Open in DBAtlas →

More from this engine