I understand that in Django, the ORM doesn’t support the ENUM type in MySQL or PostgreSQL, as this was originally a MySQL extension, and not portable across other DB types. So the two options are to use a “choices” argument to your model, or using a foreign key reference.
What are the pros and cons of these approaches?
For something like gender, I assume you would use “choices”, e.g.:
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)
...
gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
However, for something like state names, what are the reason for and against using a separate table, and foreign keys to that table?
state = models.ForeignKey(AustralianState)
Under what circumstances would you use one versus the other?
Cheers,
Victor
You should also consider foreign keys when the number of potential choices is large. That’s one of the reasons to consider using FK for countries or states. Otherwise, you’re effectively hard-coding a lot of data in your source code.