MySQL error: key specification without a key length

前端 未结 16 1380
别跟我提以往
别跟我提以往 2020-11-22 08:41

I have a table with a primary key that is a varchar(255). Some cases have arisen where 255 characters isn\'t enough. I tried changing the field to a text, but I get the foll

16条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 08:54

    I got this error when adding an index to a table with text type columns. You need to declare the size amount you want to use for each text type.

    Put the size amount within the parenthesis ( )

    If too many bytes are used you can declare a size in the brackets for varchar to decrease the amount used for indexing. This is even if you declared a size for a type already like varchar(1000). You don't need to create a new table like others have said.

    Adding index

    alter table test add index index_name(col1(255),col2(255));
    

    Adding unique index

    alter table test add unique index_name(col1(255),col2(255));
    

提交回复
热议问题