Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I specify an index for a TextField in Django with a MySql backend?

I've got a model defined in Django that looks (in part) like this:

class Info(models.Model):
    information = models.TextField(max_length = 32, null = True, db_index = True)

However, when I try syncdb with a MySql backend, I get Failed to install index for app.Info model: (1170, "BLOB/TEXT column 'information' used in key specification without a key length")

How can I fix this?

like image 888
Chris B. Avatar asked Jun 20 '12 22:06

Chris B.


1 Answers

The answer is to specify the field as a CharField, not a TextField.

class Info(models.Model):
    information = models.CharField(max_length = 32, null = True, db_index = True)
like image 110
Chris B. Avatar answered Nov 15 '22 05:11

Chris B.