Studio Rooster Studio Rooster - 1 year ago 132
Python Question

ValueError: too many values to unpack (expected 2) in Django

I am reorganizing one of my projects to be more re-usable and just generally structured better and am now getting the error below whenever I run

- I've spent half the day trying to figure this out on my own but have run out of Google results on searches and am in need of some assistance. What I've done was remove a custom user model I had setup so I can use Django's built-in User model and I also namespaced my apps urls. I don't want to include a bunch of code yet that will do nothing but dirty up this post as I am hoping the Traceback has clues that I am not seeing. If you are looking at this and have an idea of what could be the culprit for the error, can you please advice on what you need to see to offer assistance? Thank you.

Traceback (most recent call last):
File "", line 10, in <module>
File "/Users/rooster/.virtualenvs/ddm_dev/lib/python3.5/site-packages/django/core/management/", line 353, in execute_from_command_line
File "/Users/rooster/.virtualenvs/ddm_dev/lib/python3.5/site-packages/django/core/management/", line 345, in execute
File "/Users/rooster/.virtualenvs/ddm_dev/lib/python3.5/site-packages/django/core/management/", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/rooster/.virtualenvs/ddm_dev/lib/python3.5/site-packages/django/core/management/", line 399, in execute
output = self.handle(*args, **options)
File "/Users/rooster/.virtualenvs/ddm_dev/lib/python3.5/site-packages/django/core/management/commands/", line 132, in handle
File "/Users/rooster/.virtualenvs/ddm_dev/lib/python3.5/site-packages/django/db/migrations/", line 45, in changes
changes = self._detect_changes(convert_apps, graph)
File "/Users/rooster/.virtualenvs/ddm_dev/lib/python3.5/site-packages/django/db/migrations/", line 128, in _detect_changes
self.old_apps = self.from_state.concrete_apps
File "/Users/rooster/.virtualenvs/ddm_dev/lib/python3.5/site-packages/django/db/migrations/", line 166, in concrete_apps
self.apps = StateApps(self.real_apps, self.models, ignore_swappable=True)
File "/Users/rooster/.virtualenvs/ddm_dev/lib/python3.5/site-packages/django/db/migrations/", line 228, in __init__
self.render_multiple(list(models.values()) + self.real_models)
File "/Users/rooster/.virtualenvs/ddm_dev/lib/python3.5/site-packages/django/db/migrations/", line 296, in render_multiple
File "/Users/rooster/.virtualenvs/ddm_dev/lib/python3.5/site-packages/django/db/migrations/", line 585, in render
File "/Users/rooster/.virtualenvs/ddm_dev/lib/python3.5/site-packages/django/db/models/", line 158, in __new__
new_class.add_to_class(obj_name, obj)
File "/Users/rooster/.virtualenvs/ddm_dev/lib/python3.5/site-packages/django/db/models/", line 299, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/rooster/.virtualenvs/ddm_dev/lib/python3.5/site-packages/django/db/models/fields/", line 707, in contribute_to_class
super(ForeignObject, self).contribute_to_class(cls, name, virtual_only=virtual_only)
File "/Users/rooster/.virtualenvs/ddm_dev/lib/python3.5/site-packages/django/db/models/fields/", line 307, in contribute_to_class
lazy_related_operation(resolve_related_class, cls, self.remote_field.model, field=self)
File "/Users/rooster/.virtualenvs/ddm_dev/lib/python3.5/site-packages/django/db/models/fields/", line 84, in lazy_related_operation
return apps.lazy_model_operation(partial(function, **kwargs), *model_keys)
File "/Users/rooster/.virtualenvs/ddm_dev/lib/python3.5/site-packages/django/db/models/fields/", line 82, in <genexpr>
model_keys = (make_model_tuple(m) for m in models)
File "/Users/rooster/.virtualenvs/ddm_dev/lib/python3.5/site-packages/django/db/models/", line 13, in make_model_tuple
app_label, model_name = model.split(".")
ValueError: too many values to unpack (expected 2)

Answer Source

This error would only occur if split() returns more than 2 elements:

app_label, model_name = model.split(".")
ValueError: too many values to unpack (expected 2)

This means that either app_label or model_name has a dot (.) in it. My money is on the former as model names are automatically generated