''choices' must be an iterable containing (actual value, human readable name) tuples
Having an error when trying to set choices on model field. Here's the code:
TICKET = 'TICKET',
TICKET_HISTORY = 'TH'
TICKET_RATE = 'TR'
PASSWORD_CHANGE = 'PASS'
CONTENT = 'CN'
TYPE_CHOICES = [
(TICKET, 'Ticket created'), (TICKET_HISTORY, 'Ticket changed'), (TICKET_RATE, 'Ticket rated'),
(PASSWORD_CHANGE, 'Password changed'), (CONTENT, 'Added content')
]
type = models.CharField(max_length=6, choices=TYPE_CHOICES, default=TICKET)
TYPE_CHOICES seems to be correct, can't understand where's the issue with it
Exception:
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f8acad18bf8>
Traceback (most recent call last):
File "/home/userwoozer/work/tickets/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "/home/userwoozer/work/tickets/env/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/home/userwoozer/work/tickets/env/lib/python3.6/site-packages/django/core/management/base.py", line 425, in check
raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
ERRORS:
main.Activity.type: (fields.E005) 'choices' must be an iterable containing (actual value, human readable name) tuples.
Solution 1:[1]
Just remove ,
at line 1 in your code: TICKET = 'TICKET',
Solution 2:[2]
*Just dropping this here thinking it might help someone
In my case I was facing this issue while running the makemigrations command and had my choices defined like below,
ACTION_TYPE = (
(RATE_ADVISOR, 'Rate Advisor')
)
I just put a comma at the end of the choice and my issue was resolved
ACTION_TYPE = (
(RATE_ADVISOR, 'Rate Advisor'), #note this comma here
)
Solution 3:[3]
Actually this error said that You are forget to put 2 values in one of the inner tuple. This usually happens when you insert bigger size values.
Answer:
- Recheck your Inner Tuple Value.
- One of them must include 1 value or more than 2 values i.e. greater than 3 or equal.
Solution 4:[4]
The problem was that you have a col(,) after "TICKET" and that means you pass a tuple inside another one as you see!
TYPE_CHOICES = [
((TICKET), 'Ticket created'), (TICKET_HISTORY, 'Ticket changed'),
]
So this is was the problem Actually, you can use something like this
class TYPE_CHOICES(models.TextChoices):
TICKET = "TICKET", "Ticket created"
type = models.CharField(max_length=6, choices=TYPE_CHOICES.choices,
default=TYPE_CHOICES.TICKET)
Hope this helps somebody!
Solution 5:[5]
TYPE_CHOICES = (
('TICKET', 'Ticket created'),
('TICKET_HISTORY', 'Ticket changed'),
('TICKET_RATE', 'Ticket rated'),
('PASSWORD_CHANGE', 'Password changed'),
('CONTENT', 'Added content')
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Nguy?n V? Thiên |
Solution 2 | Adnan Sheikh |
Solution 3 | himanshu11sgh |
Solution 4 | Mahmoud Emad |
Solution 5 | Ahx |