7

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?

okm
  • 23,575
  • 5
  • 83
  • 90
Chris B.
  • 85,731
  • 25
  • 98
  • 139

1 Answers1

9

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)
Chris B.
  • 85,731
  • 25
  • 98
  • 139
  • 5
    CharField is sufficient here, for max_length = 32, but sometimes it's needed to create text field with no length limit (TEXT in mysql), but with limit for number of chars for index only. – kolen Sep 14 '13 at 19:41