pymysql.err.IntegrityError: (1062, "Duplicate entry 'e66672e8b1' for key 'PRIMARY'")

I am trying to create a BOM using the file import uitility and the import is erroring out with this message “pymysql.err.IntegrityError: (1062, “Duplicate entry ‘e66672e8b1’ for key ‘PRIMARY’”)”

I have a single line in the import file .

I attempted to create the BOM via the UI and encounter the same error

Regards
Sandhya

Hi,

You can find the record by executing this query.

SELECT  `name` FROM `YourDatabase`.`tabBOM Item` WHERE `name` = 'e66672e8b1'

Please take a backup before to execute the below query (highly recommended)

DELETE FROM `YourDatabase`.`tabBOM Item` WHERE `name` = 'e66672e8b1'

Thank you for your response.

I am fairly new to frappe / erpnext. Where do i run these database commands ?

Regards

Sandhya

  File "/home/frappe-admin/mconnect/apps/frappe/frappe/app.py", line 64, in application
    response = frappe.api.handle()
  File "/home/frappe-admin/mconnect/apps/frappe/frappe/api.py", line 58, in handle
    return frappe.handler.handle()
  File "/home/frappe-admin/mconnect/apps/frappe/frappe/handler.py", line 30, in handle
    data = execute_cmd(cmd)
  File "/home/frappe-admin/mconnect/apps/frappe/frappe/handler.py", line 70, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe-admin/mconnect/apps/frappe/frappe/__init__.py", line 1107, in call
    return fn(*args, **newargs)
  File "/home/frappe-admin/mconnect/apps/frappe/frappe/desk/form/save.py", line 21, in savedocs
    doc.save()
  File "/home/frappe-admin/mconnect/apps/frappe/frappe/model/document.py", line 285, in save
    return self._save(*args, **kwargs)
  File "/home/frappe-admin/mconnect/apps/frappe/frappe/model/document.py", line 307, in _save
    self.insert()
  File "/home/frappe-admin/mconnect/apps/frappe/frappe/model/document.py", line 257, in insert
    d.db_insert()
  File "/home/frappe-admin/mconnect/apps/frappe/frappe/model/base_document.py", line 344, in db_insert
    ), list(d.values()))
  File "/home/frappe-admin/mconnect/apps/frappe/frappe/database/database.py", line 147, in sql
    self._cursor.execute(query, values)
  File "/home/frappe-admin/mconnect/env/lib/python3.6/site-packages/pymysql/cursors.py", line 170, in execute
    result = self._query(query)
  File "/home/frappe-admin/mconnect/env/lib/python3.6/site-packages/pymysql/cursors.py", line 328, in _query
    conn.query(q)
  File "/home/frappe-admin/mconnect/env/lib/python3.6/site-packages/pymysql/connections.py", line 517, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/home/frappe-admin/mconnect/env/lib/python3.6/site-packages/pymysql/connections.py", line 732, in _read_query_result
    result.read()
  File "/home/frappe-admin/mconnect/env/lib/python3.6/site-packages/pymysql/connections.py", line 1075, in read
    first_packet = self.connection._read_packet()
  File "/home/frappe-admin/mconnect/env/lib/python3.6/site-packages/pymysql/connections.py", line 684, in _read_packet
    packet.check_error()
  File "/home/frappe-admin/mconnect/env/lib/python3.6/site-packages/pymysql/protocol.py", line 220, in check_error
    err.raise_mysql_exception(self._data)
  File "/home/frappe-admin/mconnect/env/lib/python3.6/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.IntegrityError: (1062, "Duplicate entry 'b85dc7f158' for key 'PRIMARY'")

SQL is no help

MariaDB [(none)]> use _7486c248390d1d77
Database changed
MariaDB [_7486c248390d1d77]> select * from tabBOM;                                                                                                                                  
Empty set (0.01 sec)

MariaDB [_7486c248390d1d77]> select * from tabBOM Item;
Empty set (0.00 sec)

MariaDB [_7486c248390d1d77]> 

@sandhyax how did you fix this issue for your site?

@Duncan_Nkhata and I’ve tried dropping, migrating, etc the site but still experienced the issue. Only this site out of several in the bench is having this issue.

@Suresh_Thakor any further ideas?

Share screen shot of your Query output.

@Suresh_Thakor This was my output from the two related tables. Let me know what else you’d like to see

MariaDB [(none)]> use _7486c248390d1d77
Database changed
MariaDB [_7486c248390d1d77]> select * from tabBOM;                                                                                                                                  
Empty set (0.01 sec)

MariaDB [_7486c248390d1d77]> select * from tabBOM Item;
Empty set (0.00 sec)

it should look like this. I think u haven’t any row in the table then how can it possible to validate primary ?

Thanks @Suresh_Thakor

We’ve resolved the issue by updating to the latest version