Add support for Index Length for MySQL-backed Models
|Reported by:||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Cc:||umbrae@…||Triage Stage:||Design decision needed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
On occasion, it is useful to be able to specific a key length different than the field length for a field - this is particularly true with MySQL, whose index sizes are limited to 767 bytes in InnoDB.
For example, I have a simple field like the following:
url = models.CharField(max_length=767, db_index=True)
Where all fields are UTF-8 characters, and hence 3 bytes each. This will issue a warning when I try to syncdb (and will full-on fail in south, as south bombs out on warnings):
_mysql_exceptions.Warning: Specified key was too long; max key length is 767 bytes
What I'd like to be able to do is the following:
url = models.CharField(max_length=767, db_index=True, index_length=255)
Which will then change the CREATE INDEX sql to look like:
CREATE INDEX "some_table_a4b49ab" ON "some_table" ("url"(255));
This should no longer issue a warning in MySQL.