ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

frappe.exceptions.ValidationError: item_code field cannot be set as unique in tabItem, as there are non-unique existing values


#1

Got this error when i ran bench update

frappe.exceptions.ValidationError: item_code field cannot be set as unique in tabItem, as there are non-unique existing values

i tried -

bench --site site1.local console
ps = frappe.get_doc("Property Setter", {"field_name": "item_code", "property": "unique"})
ps.delete()
frappe.db.commit()

Result

DoesNotExistError: Property Setter {u'property': u'unique', u'field_name': u'item_code'} not found

Update failure from v10 to v11
#2

Have you set Item Code field as unique in Item DocType ? If yes then uncheck it as you have Item records with same Item Code. Also, do bench build && bench migrate.


#3

I am not able to login to an instance

i m getting the following message
Your system is being updated. Please refresh again after a few moments


#4

Make sure to maintain adequate backup!
Try

bench update --force --reset
bench update --requirements
bench update --patch

#5

I am still getting the following error

File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 768, 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 258, in on_update
    raise e
frappe.exceptions.ValidationError: item_code field cannot be set as unique in tabItem, as there are non-unique existing values`Preformatted text`

#6
cd ~/frappe-bench # or your bench path
cd apps/frappe && git fetch upstream && git checkout master && cd -
cd apps/erpnext && git fetch upstream && git checkout master && cd -
bench update --requirements
bench update --patch

post error logs to pastebin, so that I can help troubleshoot.


#7

https://pastebin.com/Ac41bXaZ


#8

Run following sequence, your frappe database .sql file was not able to process properly.

cd ~/frappe-bench # or your bench path
cd apps/frappe && git clean -df && git fetch upstream && git checkout master && cd -
bench update --requirements
bench update --patch

Next time, also include command followed by error log (if you encounter error)
Please also share following logs, if above cmds fails.

cd ~/frappe-bench # or your bench path
tail 100 ./logs/node-socketio.error.log
tail 100 ./logs/worker.error.log
tail 100 ./logs/web.error.log
tail 100 ./logs/redis-cache.error.log
tail 100 ./logs/redis-socketio.error.log
tail 100 ./logs/web.error.log

#9

None of the commands help in resolution of the issue…


#10

In post # 2 above Sangram’s advice seems worth a try.

anand gives similar advice and also a PR fix to refine a validation to prevent that case.

To identify exactly what non-unique Item records are causing the problem might help clarify your problem case. To inspect the database would require sql skills.