honzakral / django-threadedcomments

django-threadedcomments is a simple yet flexible threaded commenting system for Django.
BSD 3-Clause "New" or "Revised" License
622 stars 165 forks source link

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

Closed pkarp0 closed 8 years ago

pkarp0 commented 9 years ago

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. treepath = 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.

vdboor commented 9 years ago

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

pkarp0 commented 9 years ago

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

pkarp0 commented 9 years ago

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

vdboor commented 9 years ago

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 030b67ff412661033e3585ab7cfe2f316a4fe102

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

pkarp0 commented 9 years ago

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.

khs8727 commented 9 years ago

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!

vdboor commented 8 years ago

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