houhou
houhou

Reputation: 177

'choices' must be an iterable containing (actual value, human readable name) tuples django 3.1

whene i want to makemigration it show me this error

user.User.allowd_to_take_appointement: (fields.E005) 'choices' must be an iterable containing (actual value, human readable name) tuples.
user.User.type_of_user: (fields.E005) 'choices' must be an iterable containing (actual value, human readable name) tuples.

this is my models.py

class TypeOfUser(models.TextChoices):
    PATIENT = 'patient', 'Patient'
    DOCTOR = 'doctor', 'Doctor'
    RECEPTION = 'reception', 'Reception'
    TEMPORARY = 'temporary', 'Temporary'

class AllowdToTakeAppointement(models.TextChoices):
    YES = ('yes', 'Yes')
    NO = ('no', 'No')

class User(AbstractUser):
    type_of_user = models.CharField(max_length=200, choices=TypeOfUser, default=TypeOfUser.PATIENT)
    allowd_to_take_appointement = models.CharField(max_length=20, choices=AllowdToTakeAppointement, default=AllowdToTakeAppointement.YES)

    def is_doctor(self):
        return self.type_of_user == TypeOfUser.DOCTOR

    def can_add_appointment(self):
        return self.type_of_user == AllowdToTakeAppointement.YES

i'm using django 3.1

Upvotes: 1

Views: 1177

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476699

The choices=… should be provided the outcome of the .choices property of your TypeOfUser and AllowdToTakeAppointment:

class User(AbstractUser):
    type_of_user = models.CharField(
        max_length=200,
        #            .choices ↓
        choices=TypeOfUser.choices,
        default=TypeOfUser.PATIENT
    )
    allowd_to_take_appointement = models.CharField(
        max_length=20,
        #                          .choices ↓
        choices=AllowdToTakeAppointement.choices,
        default=AllowdToTakeAppointement.YES
    )

    def is_doctor(self):
        return self.type_of_user == TypeOfUser.DOCTOR

    def can_add_appointment(self):
        return self.type_of_user == AllowdToTakeAppointement.YES

Upvotes: 1

Related Questions