Django: ValueError: too many values to unpack

This post is more than 15 years old.

Posted at 15:01 on 27 December 2008

I came across this error this morning on a Django project that I'm working on in my spare time. I was trying to add some custom permissions to one of the models, as outlined in the documentation, only to have it choke with this message when I ran manage.py syncdb.

A bit of Googling got me to this site, but unfortunately it's in Polish. Never mind, Google Translate managed to give me enough information. Turns out that I had missed out a comma that I didn't think was necessary:

class Meta:
  permissions = (
    ("can_drive", "Can drive"),
    ("can_vote", "Can vote in elections"),
    ("can_drink", "Can drink alcohol"),   # <== This comma is important!
  )

Hmmm, I always thought that last comma in Python was only an optional extra in case you decided to add an extra item to the end of a tuple and forgot to add it in to the previous line. Seems it does have some obscure but significant semantic importance after all.