I create a model for multiple choice question. Each question has 5 choice of answers. And I need each question object to be unique based on it's question and answers. And so, I design the model like this.
from django.db import models
class MultipleChoiceQuestion(models.Model):
ANSWERS = [('a', 'a'), ('b', 'b'), ('c', 'c'), ('d', 'd'), ('e', 'e')]
question = models.TextField()
a = models.TextField()
b = models.TextField()
c = models.TextField()
d = models.TextField()
e = models.TextField()
true_answer = models.CharField(max_length=1, choices=ANSWERS)
class Meta:
unique_together = [('question', 'a', 'b', 'c', 'd', 'e')]
When I run migrate
, mysql give this error:
1170, "BLOB/TEXT column 'question' used in key specification without a key length"
I found this error has been discussed here. But, I can't use
CharField
with it's small limit, because I need to store long text
(until 10000 char or more).
sqlite3 and postgresql can do this (i mean django didn't complain about
key specification for TEXT
).
The reason I need to use mysql because the server where I will deploy this django app is only provide mysql, no postgresql.
So, is there anyway I could achieve this?