Getting DuplicateEntryError when trying to install Custom App on remote server

Hello,

As I am not able to update changes made to my Custom App I used following commands to remove it and then reinstall it.

bench rm mymfg
bench migrate
bench restart
bench get-app --resolve-deps mymfg https://github.com/xxxx/mymfg.git
bench install-app mymfg

When I issue the command bench install-app mymfg Bench is giving following errors

vmi934079:~/erp13$ bench install-app mymfg

Installing mymfg...

An error occurred while installing mymfg: ('Module Def', 'My Mfg', IntegrityError(1062, "Duplicate entry 'My Mfg' for key 'PRIMARY'"))

Traceback (most recent call last):
  File "apps/frappe/frappe/model/base_document.py", line 400, in db_insert
    frappe.db.sql(
  File "apps/frappe/frappe/database/database.py", line 174, in sql
    self._cursor.execute(query, values)
  File "env/lib/python3.10/site-packages/pymysql/cursors.py", line 148, in execute
    result = self._query(query)
  File "env/lib/python3.10/site-packages/pymysql/cursors.py", line 310, in _query
    conn.query(q)
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 548, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 775, in _read_query_result
    result.read()
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 1156, in read
    first_packet = self.connection._read_packet()
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 725, in _read_packet
    packet.raise_for_error()
  File "env/lib/python3.10/site-packages/pymysql/protocol.py", line 221, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "env/lib/python3.10/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.IntegrityError: (1062, "Duplicate entry 'My Mfg' for key 'PRIMARY'")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "apps/frappe/frappe/commands/site.py", line 293, in install_app
    _install_app(app, verbose=context.verbose)
  File "apps/frappe/frappe/installer.py", line 184, in install_app
    add_module_defs(name)
  File "apps/frappe/frappe/installer.py", line 496, in add_module_defs
    d.save(ignore_permissions=True)
  File "apps/frappe/frappe/model/document.py", line 310, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 332, in _save
    return self.insert()
  File "apps/frappe/frappe/model/document.py", line 276, in insert
    raise e
  File "apps/frappe/frappe/model/document.py", line 273, in insert
    self.db_insert()
  File "apps/frappe/frappe/model/base_document.py", line 425, in db_insert
    raise frappe.DuplicateEntryError(self.doctype, self.name, e)
frappe.exceptions.DuplicateEntryError: ('Module Def', 'My Mfg', IntegrityError(1062, "Duplicate entry 'My Mfg' for key 'PRIMARY'"))

Please help solve this issue.

TIA

Yogi Yang

Please apply and check it.

bench clear-cache
bench --site [your_site_name] install-app mymfg
bench migrate
bench clear-cache

Hello,

Still getting the same error. I am using the following.

bench --site erp13 install-app mymfg

TIA

Yogi Yang

Hello,

Is there any way by which we can manually correct the error DuplicateEntryError to be able to install Custom App in ERPNext 13?

TIA

Yogi Yang

Please apply it in bench console

frappe.delete_doc('Module Def', 'My Mfg')
frappe.db.commit()

Then

bench migrate
bench clear-cache
bench --site [your_site_name] install-app mymfg
bench build
bench update --patch
bench migrate
bench clear-cache

Hope you help it.

Thank You!

3 Likes