Closed carcleo closed 2 years ago
from django.db import models
from enum import Enum
#pip install django-mysql
from django_mysql.models import EnumField
class options(models.TextChoices):
Sim = "Sim"
Não = "Não"
class Cliente(models.Model) :
block = EnumField(choices=options.choices, default= 'Não')
def __str__(self):
return self.name
In MySQL there are several types of data, char, varchar int, boolean as you already know.
But it also has the Enum type that in SQL we create the table as follows:
My goal is, when I'm creating the models in Django (Python) to be able to create the tables in MySQL I can automatically create this type of field as well.
I tried like this:
Create the field in MySQL creates but creates as VARCHAR(3) and not as enum.
Can Django do this? How would it be?
I wouldn't like to have to create the tables directly in the database,