Friday 15 June 2012

sql - MySQL error: key specification without a key length -


I have a table with the primary key that is a varchar (255) in some instances where 255 characters are not enough I tried to convert the field to text, but I got the following error:

  Blob / Text column is used without the length of the 'message_id' key  

How can I fix this?

Edit: I should also indicate that this table has an overall primary key with multiple columns.

The error occurs because MySQL can only point to N characters before a Blob or TEXT column . Therefore, error occurs primarily when there is a field / column type of text or blob, or those readers or blob types such as TINYBLOB, MEDIUMBLOB, LONGBOLOB, TINYTEXT, MEDIUMTEXT, and LONGTEXT such as the primary key or index form Let's try. With full blob or text without length, MySQL is unable to guarantee the specificity of the column because it is variable and dynamic size. Therefore, when using the BLOB or TEXT type as an index, the value of N should be given so that the MySQL key can determine the length. However, MySQL does not support a major length limit on TEXT or BLOB. Lesson (88) just will not work.

When you try to change the non-TEXT and non-BLOB types such as VARCHAR and ENUM to the table column in text or Blob type, it will also pop up, already unique barriers with columns or The index was defined as. Eltter SQL SQL command will fail.

The solution to the problem is to remove the index or Blob column from the index or unique barrier, or to set other fields as primary keys. If you can not do this, and want to set a limit on the text or blob column, use the VARCHAR type and set the length limit on it. By default, VARCHAR is limited to 255 characters and its announcement It should be specified within a bracket immediately after its manifestation, i.e. VARCHAR (200) will restrict it to only 200 characters.

Occasionally, even if you do not use text or blob related type in your table, error 1170 may also be visible. In a situation where you specify the VARCHAR column as the primary key, but set its length or size of the letter incorrectly. VARCHAR accepts only 256 characters, so anything like VARCHAR (512) can force MySQL to auto-converge VARCHAR (512) into a SMARTTEXT datatype, which can later be used on key length with 1170 error If the column primary key or unique or non-unique index to resolve this problem, specify the figure of less than 256 as the size of the VARCHAR field.

Reference:


No comments:

Post a Comment