Reputation: 475
Strange question, I have been creating database tables on my local mysql for years now, and I have just got an error message:
Specified key was too long; max key length is 767 bytes
The column at fault is the following:
`referenceperiod` VARCHAR(300) NULL
notice the length of 300, which, the last time I checked is less then 767. I have an index on this column which if I remove allows the table to be built:
INDEX `idx_referenceperiod` (referenceperiod),
The strange thing is, this is not the first time I have built this exact table - so why is it suddenly failing now...
Upvotes: 1
Views: 44
Reputation: 116160
If you have a UTF8 collation, MySQL reserves 3 bytes for each character, in which case the key becomes 900 bytes in total.
900 is more than 767, last time I checked. ;)
Upvotes: 2