1

I have a working project and I would like to add one new field to one of the models. I have added the new field and ran the makemigrations command and then I got ValueError: too many values to unpack

This is the model:

class Line(models.Model):                     
    name = models.CharField(max_length=250, null=False, blank=False, unique=True)
    label_name = models.CharField(max_length=250, null=True, blank=True, unique=True)

and I wanted to add this field:

link = models.CharField(max_length=200,null=True,blank=True, unique=True)

Then I ran makemigrations command, and got this exception exception:

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2017.3.3\helpers\pycharm\django_manage.py", line 52, in <module>
    run_command()
  File "C:\Program Files\JetBrains\PyCharm 2017.3.3\helpers\pycharm\django_manage.py", line 46, in run_command
    run_module(manage_file, None, '__main__', True)
  File "C:\Python27\lib\runpy.py", line 176, in run_module
    fname, loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 82, in _run_module_code
    mod_name, mod_fname, mod_loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "F:\cellular_resolution_map_of_larval_zebrafish\manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 342, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "C:\Python27\lib\site-packages\django\core\management\commands\makemigrations.py", line 105, in handle
    loader.project_state(),
  File "C:\Python27\lib\site-packages\django\db\migrations\loader.py", line 338, in project_state
    return self.graph.make_state(nodes=nodes, at_end=at_end, real_apps=list(self.unmigrated_apps))
  File "C:\Python27\lib\site-packages\django\db\migrations\graph.py", line 280, in make_state
    project_state = self.nodes[node].mutate_state(project_state, preserve=False)
  File "C:\Python27\lib\site-packages\django\db\migrations\migration.py", line 88, in mutate_state
    operation.state_forwards(self.app_label, new_state)
  File "C:\Python27\lib\site-packages\django\db\migrations\operations\fields.py", line 51, in state_forwards
    state.reload_model(app_label, self.model_name_lower)
  File "C:\Python27\lib\site-packages\django\db\migrations\state.py", line 148, in reload_model
    self.apps.render_multiple(states_to_be_rendered)
  File "C:\Python27\lib\site-packages\django\db\migrations\state.py", line 296, in render_multiple
    model.render(self)
  File "C:\Python27\lib\site-packages\django\db\migrations\state.py", line 585, in render
    body,
  File "C:\Python27\lib\site-packages\django\db\models\base.py", line 158, in __new__
    new_class.add_to_class(obj_name, obj)
  File "C:\Python27\lib\site-packages\django\db\models\base.py", line 299, in add_to_class
    value.contribute_to_class(cls, name)
  File "C:\Python27\lib\site-packages\django\db\models\fields\related.py", line 702, in contribute_to_class
    super(ForeignObject, self).contribute_to_class(cls, name, virtual_only=virtual_only)
  File "C:\Python27\lib\site-packages\django\db\models\fields\related.py", line 308, in contribute_to_class
    lazy_related_operation(resolve_related_class, cls, self.remote_field.model, field=self)
  File "C:\Python27\lib\site-packages\django\db\models\fields\related.py", line 85, in lazy_related_operation
    return apps.lazy_model_operation(partial(function, **kwargs), *model_keys)
  File "C:\Python27\lib\site-packages\django\db\models\fields\related.py", line 83, in <genexpr>
    model_keys = (make_model_tuple(m) for m in models)
  File "C:\Python27\lib\site-packages\django\db\models\utils.py", line 13, in make_model_tuple
    app_label, model_name = model.split(".")
ValueError: too many values to unpack

How can I solve it?

Thank you very much.

The Maestro
  • 659
  • 1
  • 5
  • 21
  • 1
    Can you share the relevant migration file? – Willem Van Onsem Jul 19 '18 at 13:39
  • 2
    that's not a migrations error. Is your code running normally without the migrations? Check you latest code especially where you execute calls against models, so that all the fields would be correctly presented, ex: Model.objects.get(field='this') instead of Model.objects.get('this'). – Dmitrii G. Jul 19 '18 at 13:44
  • @WillenVanOnsem No file was created. – The Maestro Jul 19 '18 at 13:54
  • @DimitriiG The code is running perfectly fine before making the new migrations, and after failing in making them it is still working well – The Maestro Jul 19 '18 at 13:57
  • And also you have `max_length=500` and `unique=True` in `link = models.CharField(max_length=500,null=True,blank=True, unique=True)`. It is incorrect. [Django docs](https://docs.djangoproject.com/en/dev/ref/databases/#notes-on-specific-fields) says _**Any fields that are stored with VARCHAR column types have their max_length restricted to 255 characters if you are using unique=True for the field._** – Max Jul 19 '18 at 14:06
  • @JonhyBeebop THanks for the information I have corrected it but still getting the same error – The Maestro Jul 19 '18 at 14:09
  • is that the only model change? and are you adding any new app? – doubleo46 Jul 19 '18 at 14:50
  • check this one https://stackoverflow.com/questions/37244808/valueerror-too-many-values-to-unpack-expected-2-in-django – doubleo46 Jul 19 '18 at 14:59
  • @doubleo46 Thanks that solved my problem but not the accepted answer but Artekis's answer. – The Maestro Jul 19 '18 at 15:53

0 Answers0