Frappe.exceptions.ValidationError: quotation_to field cannot be set as unique in tabQuotation, as there are non-unique existing values

I ran into following issue and update, migrate nothing seems to work, site is down with we are upgrading message.:

Updating frappe                     : [========================================]
Updating erpnext                    : [==============                          ]Traceback (most recent call last):
  File "/usr/lib64/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 79, in <module>
    main()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 16, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 700, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 680, in main
    rv = self.invoke(ctx)
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 1027, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 1027, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 873, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 508, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python2.7/site-packages/click/decorators.py", line 16, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands.py", line 29, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands.py", line 215, in migrate
    frappe.model.sync.sync_all(verbose=context.verbose)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/sync.py", line 19, in sync_all
    sync_for(app, force, verbose=verbose)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/sync.py", line 43, in sync_for
    import_file_by_path(doc_path, force=force)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 54, in import_file_by_path
    import_doc(doc, force=force, data_import=data_import, pre_process=pre_process)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 122, in import_doc
    doc.insert()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 210, in insert
    self.run_post_save_methods()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 607, in run_post_save_methods
    self.run_method("on_update")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 551, in run_method
    return Document.hook(fn)(self, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 706, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 689, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 545, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py", line 111, in on_update
    updatedb(self.name)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/db_schema.py", line 68, in updatedb
    tab.sync()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/db_schema.py", line 135, in sync
    self.alter()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/db_schema.py", line 315, in alter
    frappe.throw(_("{0} field cannot be set as unique in {1}, as there are non-unique existing values".format(fieldname, self.name)))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 257, in throw
    msgprint(msg, raise_exception=exc)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 250, in msgprint
    _raise_exception()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 235, in _raise_exception
    raise raise_exception, encode(msg)
frappe.exceptions.ValidationError: quotation_to field cannot be set as unique in tabQuotation, as there are non-unique existing values

Hi Yashodhan,

You should remove the unique checkbox on quotation_to by going to:

bench --site {yoursite} console

In the ipython console:

ps = frappe.get_doc("Property Setter", {"field_name": "quotation_to", "property": "unique"})
ps.delete()
frappe.db.commit()
3 Likes

@anand Thank you so much… it worked perfectly…

Any idea why this happened? What should be avoided?

I think it needs to be validated. I will push a fix in some time to prevent this from happening.

1 Like

Here’s the pull request: [fix] Validate if non-unique values exist if Unique is checked by anandpdoshi · Pull Request #1421 · frappe/frappe · GitHub

1 Like

Hi Anand,

I came across a similar issue like:

Frappe.exceptions.ValidationError: quotation_to field cannot be set as unique in tabQuotation, as there are non-unique existing values

where I added some check fields in the ITEM form and accidently marked one field (Article) as unique and got the message back “article field cannot be set as unique in tabItem, as there are non-unique existing values”

Could you please give the correct instruction, to resolve this issue?


Update: while searching through the programm, discovered the function “Custom Field/Item-article” and could resolve the unique check box there.

Thanks, Gerard

Hi @anand,

I am getting the same issue.

Can you please advise how to resolve it since we cannot process updating our system to V8.
Thank you…

Hi Ananad,

i am also facing the same issue

frappe.exceptions.ValidationError: Options must be a valid DocType for field Print Style in row 17

You are our Saviour ! It Worked Thank you very much :slight_smile: