Getting DuplicateEntryError when trying to install Custom App on remote server


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
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/", line 400, in db_insert
  File "apps/frappe/frappe/database/", line 174, in sql
    self._cursor.execute(query, values)
  File "env/lib/python3.10/site-packages/pymysql/", line 148, in execute
    result = self._query(query)
  File "env/lib/python3.10/site-packages/pymysql/", line 310, in _query
  File "env/lib/python3.10/site-packages/pymysql/", line 548, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "env/lib/python3.10/site-packages/pymysql/", line 775, in _read_query_result
  File "env/lib/python3.10/site-packages/pymysql/", line 1156, in read
    first_packet = self.connection._read_packet()
  File "env/lib/python3.10/site-packages/pymysql/", line 725, in _read_packet
  File "env/lib/python3.10/site-packages/pymysql/", line 221, in raise_for_error
  File "env/lib/python3.10/site-packages/pymysql/", 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/", line 293, in install_app
    _install_app(app, verbose=context.verbose)
  File "apps/frappe/frappe/", line 184, in install_app
  File "apps/frappe/frappe/", line 496, in add_module_defs
  File "apps/frappe/frappe/model/", line 310, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/", line 332, in _save
    return self.insert()
  File "apps/frappe/frappe/model/", line 276, in insert
    raise e
  File "apps/frappe/frappe/model/", line 273, in insert
  File "apps/frappe/frappe/model/", line 425, in db_insert
    raise frappe.DuplicateEntryError(self.doctype,, e)
frappe.exceptions.DuplicateEntryError: ('Module Def', 'My Mfg', IntegrityError(1062, "Duplicate entry 'My Mfg' for key 'PRIMARY'"))

Please help solve this issue.


Yogi Yang

Please apply and check it.

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


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

bench --site erp13 install-app mymfg


Yogi Yang


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


Yogi Yang

Please apply it in bench console

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


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!