[Django]-TypeError: 'UniqueConstraint' object is not iterable in Django

2👍

The error simply means that it is not iterable. Try to define it like this

For example

class Meta:
    constraints = [models.UniqueConstraint(fields['app_uuid', 'version_code'], name='unique appversion')]

5👍

You need to assign iterable to the constraints. You are missing , in (models.UniqueConstraint(...),), which means you are assigning models.UniqueConstraint instance instead of tuple.

class Meta:
    constraints = (models.UniqueConstraint(fields=['student', 'classroom', 'code'], name='student_classroom_code'),)

0👍

Python tuples need at least one , before closing. If you dont specify this ,, the interpreter take it for a group and the type will be the var inside the parenthesis

Example:

t = ('i am a tuple',)         # this is good
t = ('i am not a tuple')      # this is bad

Leave a comment