: ('Module Def', 'Accounts', IntegrityError(1062, "Duplicate entry 'Accounts' for key 'PRIMARY'"))

Bench –site new-site install-app erpnext fails DuplicateEntryError: (‘Module Def’, ‘Accounts’, IntegrityError(1062, “Duplicate entry ‘Accounts’ for key ‘PRIMARY’”))

Installing erpnext…
An error occurred while installing erpnext: (‘Module Def’, ‘Accounts’, IntegrityError(1062, “Duplicate entry ‘Accounts’ for key ‘PRIMARY’”))
Traceback (most recent call last):
File “apps/frappe/frappe/model/base_document.py”, line 494, in db_insert
frappe.db.sql(
File “apps/frappe/frappe/database/database.py”, line 221, 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 ‘Accounts’ 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 450, in install_app
_install_app(app, verbose=context.verbose, force=force)
File “apps/frappe/frappe/installer.py”, line 291, in install_app
add_module_defs(name, ignore_if_duplicate=force)
File “apps/frappe/frappe/installer.py”, line 622, in add_module_defs
d.insert(ignore_permissions=True, ignore_if_duplicate=ignore_if_duplicate)
File “apps/frappe/frappe/model/document.py”, line 278, in insert
self.db_insert(ignore_if_duplicate=ignore_if_duplicate)
File “apps/frappe/frappe/model/base_document.py”, line 521, in db_insert
raise frappe.DuplicateEntryError(self.doctype, self.name, e)
frappe.exceptions.DuplicateEntryError: (‘Module Def’, ‘Accounts’, IntegrityError(1062, “Duplicate entry ‘Accounts’ for key ‘PRIMARY’”))

Did you get a Solution ? I am also facing a same issue.

The solution could be just updating with

bench update

other solution is to purge the app Accounts from erpnext like this post, but you will not be able to use Accounts Model