MySQL operation error message "BLOB / TEXT column request_data in key specification without a key length" solution to add mysql field index failed BLOB / TEXT column 'col2' used in key specification without a key length

wrong reason:

       Access to information to know, before the original Mysql database for BLOB / TEXT data types such structures can only index N characters. So this can not serve as the primary key data type, nor is the UNIQUE. So VARCHAR to be replaced, but the size of type VARCHAR nor greater than 255, when the field of type VARCHAR if the size is greater than 255 will be converted into small TEXT process. It is also a problem.

 Solution:

Read the data structure of the table is a text field type found request_data

The next query is found:. MySQL can only BLOB / TEXT type field is set index for the money BLOB / TEXT N characters index data specified under request_data length on it:

alter table foo add index request_data (request_data(10))

Joint index

alter table testcase add unique index(request_url,request_data(100));

 Before executing this sql remove all heavy data tables, delete sql as follows:

DELETE testcase
FROM
 testcase, 
 (
  SELECT
  max(id) id,
  api_purpose,
request_url,
  request_data,
assert_method,
check_point,
correlation,
active,
creater 
  FROM
   testcase
  GROUP BY
  api_purpose,
request_url,
  request_data,
assert_method,
check_point,
correlation,
active,
creater
  HAVING
   count(*) > 1
 ) T2
WHERE
 testcase.api_purpose = t2.api_purpose 
 and testcase.api_purpose = t2.api_purpose 
 and testcase.request_url = t2.request_url 
 and testcase.request_data = t2.request_data 
 and testcase.assert_method = t2.assert_method 
 and testcase.check_point = t2.check_point 
 and testcase.correlation = t2.correlation 
 and testcase.active = t2.active 
 and testcase.creater = t2.creater 
 and testcase.id <t2.id;

 

 

 

Reference article:

This error causes said very clearly

MySQL operation error message "BLOB / TEXT column used in key specification without a key length" solution

This is the solution:

Add mysql field index failed BLOB / TEXT column 'col2' used in key specification without a key length

Guess you like

Origin www.cnblogs.com/kaerxifa/p/11965981.html