Opened 17 years ago
Closed 17 years ago
#7750 closed (duplicate)
TextField in unique_together breaks with MySQL BLOB index without index key length
| Reported by: | benjaoming | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Keywords: | unique_together | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
I get this exception:
_mysql_exceptions.OperationalError: (1170, "BLOB/TEXT column 'text' used in key specification without a key length")
I'm not quite sure about what's the right thing to do. Apparently a text field can't be used in key combinations in MySQL and probably neither in other SQL flavors. So maybe Django should raise an exception and/or the documentation should include which kinds of fields that are valid for the unique_together meta attribute.
An example could be:
class Messages(models.model)
subject = models.CharField(max_length=20)
msg = models.TextField
class Meta:
unique_together = ("subject", "msg")
Change History (2)
comment:1 by , 17 years ago
comment:2 by , 17 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
| Summary: | TextField in unique_together → TextField in unique_together breaks with MySQL BLOB index without index key length |
Duplicate of the quite old bug #2495. The easy work-around is to leave unique=True off the model, and run ALTER TABLE manually to add the unique constraint.
Sorry. That wasn't a runnable example. This one is:
class Message(models.Model): subject = models.CharField(max_length=20) msg = models.TextField() class Meta: unique_together = ("subject", "msg")