Search code examples
ubuntuerpnextfrappe

How to solve duplicate entry error while installing packages/modules in erpnext, eg indain_compliance module


Hey I have been trying to install indian_compliance module on my ubuntu vm for use on erpnext using the following commands in terminal:

bench get-app https://github.com/resilient-tech/india-compliance.git
bench install-app india_compliance

but it failed once for some reason and a folder got created in home\frappe-bench\apps\indian_compliance

then on retrying the same command was getting this error:

raise frappe.DuplicateEntryError(self.doctype, self.name, e)
frappe.exceptions.DuplicateEntryError: ('Module Def', 'GST India', IntegrityError(1062, "Duplicate entry 'GST India' for key 'PRIMARY'"))

but then tried deleting the folder but still getting the same error code

Before this I was facing similar error while installing erpnext

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 510, in db_insert
    frappe.db.sql(
  File "apps/frappe/frappe/database/database.py", line 229, in sql
    self._cursor.execute(query, values)
  File "env/lib/python3.10/site-packages/pymysql/cursors.py", line 158, in execute
    result = self._query(query)
  File "env/lib/python3.10/site-packages/pymysql/cursors.py", line 325, in _query
    conn.query(q)
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 549, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 779, in _read_query_result
    result.read()
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 1157, in read
    first_packet = self.connection._read_packet()
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 729, 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 463, 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 279, in insert
    self.db_insert(ignore_if_duplicate=ignore_if_duplicate)
  File "apps/frappe/frappe/model/base_document.py", line 537, 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'"))

but the only solution I found was to to make a completely new machine !! from scratch i have faced this error quite a few times and it has become a hassle to create an entire new machine again, there must be a way to solve such error, like somehow deleting it from the mysql database on the machine, but was not able to figure much out

mysql -u root -p
SHOW DATABASES;
USE database_name_here;
SHOW TABLES;

then what to do next how to find the duplicate entry is what i am not able to do


Solution

  • I was facing similar error, the way I solved was by finding the duplicate packages in mysql and deleting them, in your case too this should work, you mysql steps are infact correct to a point first follow them again:

    mysql -u root -p
    SHOW DATABASES;
    USE database_name_here;
    SHOW TABLES;
    

    then

    SELECT * FROM `tabModule Def`;
    DELETE FROM `tabModule Def` WHERE app = 'Indian Compliance';
    

    then the install commands should run!!