Search code examples
mysqlspring-data-jpaeclipselink

Spring data causing MySQL max key length exceeded


I have the following code segment (generated by Spring Data / Eclipselink)

    CREATE TABLE abnormal_flags (ID BIGINT NOT NULL, code VARCHAR(255) NOT NULL 
UNIQUE, created DATETIME NOT NULL, description VARCHAR(255) NOT NULL, uuid 
LONGBLOB NOT NULL UNIQUE, PRIMARY KEY (ID));

With MySQL it results in the following:

ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes

This is the connection string:

jdbc:mysql://localhost/mynewdb?
useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false
&serverTimezone=UTC

I have seen and resolved this before, however in this case I am not able to see where the issue is? Is it because the uuid has been converted to a longblob? I can't see why this would be an issue as it is not a key?

I removed the unique constraint on uuid with the same result

Apologies if I am the victim of a brain fade!


Solution

  • ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes

    The above exception is clear enough, you have hit the limit.

    Change varchar(255) to something below to 255, eg varchar(191)