honzakral/django-threadedcomments

_mysql_exceptions.Warning: Specified key was too long; max key length is 767 bytes

Closed this issue · 7 comments

During the migration 0001_initial the mysql engine reports the following error/warning:
_mysql_exceptions.Warning: Specified key was too long; max key length is 767 bytes

This is caused by the tree_path field of max_length=500 and a db_index which apparently exceeds the hard limit of 767.
tree_path = models.CharField(_('Tree path'), max_length=500, editable=False, db_index=True)

The migration fails to complete yet the table and an index on tree_path are created. MySQL will truncate the index keys.

We've fixed this issue in the latest beta release. You can install it using pip install django-threadedcomments==1.0b1

The reason this exceeds the limit, is because MySQL's utf8 support uses 3 bytes per character. So you get 3*255 = 765 < 767, and when an index needs 256 or more, MySQL bails out

I should have mentioned this in the comment. We are using threadedcomments==1.0b1 and django1.6

How was this fixed? Was the max_length reduced or the db_index removed?

My apologies, I've reopened the ticket!

Previously the field was a TextField, which MySQL didn't like.
Now it's configured a charfield, see 030b67f

However, with utf-8 enabled (which you should have for any sensible website), I guess this is still not good enough. I guess we'd either have to remove the index, or reduce the max length

Thanks. There is one other solution which is to modify the initial migration to use raw sql to generate the index. I'll send a PR when I have this working.

Hi, Did you fix this problem? if so, could you release the updated version?
I am using Django (1.8.2), django-threadedcomments (1.0b1), and MySQL.

Thanks!

There was another fix for this after 1.0b1 - which is now released in the 1.0 release. Please try this release, and let me know when it still doesn't work