MySQL throws Error 1170 when a BLOB or TEXT column is placed in an index or primary key without specifying a prefix length.
MySQL Error 1170: ER_BLOB_KEY_WITHOUT_LENGTH occurs when you try to index a BLOB or TEXT column without a prefix length. Define an explicit length such as VARCHAR(255) or add a key prefix (e.g., KEY(col(100))) to resolve the issue.
BLOB/TEXT column '%s' used in key specification without a
The exact message is: ERROR 1170 (42000): BLOB/TEXT column 'col_name' used in key specification without a key length
.
MySQL raises this schema definition error when you attempt to create an index, UNIQUE key, or PRIMARY KEY that includes a BLOB or TEXT column without defining a prefix length.
The storage engine needs a fixed number of bytes to store index values.
BLOB and TEXT types are variable length, so MySQL requires you to specify how many initial bytes should be indexed.
This error usually appears during CREATE TABLE
or ALTER TABLE ... ADD INDEX
statements that list a BLOB/TEXT field directly.
Add a prefix length to the BLOB/TEXT column inside the index definition.
The prefix determines how many characters (bytes) are stored in the index.
If full-text search is not needed, convert the column to a fixed-length type such as VARCHAR(191)
for utf8mb4 compatibility.
During schema migrations, developers often refactor VARCHAR
to TEXT
but forget to adjust existing indexes, triggering Error 1170.
In composite keys, the BLOB/TEXT column may come after other fields.
Every variable-length part needs its own prefix length.
Always review column types before adding them to keys. For variable-length data, decide the minimal prefix that maintains selective indexing while saving space.
Automate schema checks with tools like Galaxy’s linter, which flags index definitions missing key lengths before deployment.
Error 1071: Key is too long. Resolve by shortening indexed columns or changing the storage engine.
Error 1709: Index column size too large.
Use smaller prefix lengths or switch to InnoDB file-format Barracuda with DYNAMIC/COMPRESSED row format.
.
The engine must know how many bytes to store in the index. Without a fixed size, it cannot allocate space efficiently.
Select the shortest length that keeps the index selective. For utf8mb4 columns, 191 characters fits within InnoDB limits.
No. Regular indexes require a prefix. Use FULLTEXT indexes when you need to search the entire column.
Galaxy’s schema-aware linter flags BLOB/TEXT index definitions lacking prefix lengths before you run them.