Error While install ERPNEXT : DuplicateEntryError

Hello Guys!

I created new site and installed ERPNEXT that time i am receiving below error.

frappe.exceptions.DuplicateEntryError: (u'Module Def', u'Accounts', IntegrityError(1062, "Duplicate entry 'Accounts' for key 'PRIMARY'"))

I have take latest pull ERPNext and Frappe.
erpnext 10.1.4
frappe 10.0.25

Please help me.

Thanks.

Hi @Ketan.ERPNext,

could you please share some more details? When you write ā€œnew siteā€ is it bench new-site and you are running a multi-tenant? Or is it a new installation with the easy install script? What would be steps to reproduce your issue? I would guess something in the db went wrong and you have duplicate modules loadedā€¦

Hi @lasalesi,

Thanks for reply!

I have followed below steps:

steps:1 /workspace/erp_project/frappe-bench/apps/erpnext$ git pull origin ā€œbranch nameā€
steps:2 /workspace/erp_project/frappe-bench/apps/erpnext$ git pull up develop
steps:3 bench new-site site1.dev
steps:4 bench --site site1.dev install-app erpnext

Installing erpnext...
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/workspace/erp_project/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 94, in <module>
    main()
  File "/home/workspace/erp_project/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/home/workspace/erp_project/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/workspace/erp_project/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/workspace/erp_project/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/workspace/erp_project/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/workspace/erp_project/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/workspace/erp_project/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/workspace/erp_project/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/workspace/erp_project/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 24, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/workspace/erp_project/frappe-bench/apps/frappe/frappe/commands/site.py", line 165, in install_app
    _install_app(app, verbose=context.verbose)
  File "/home/workspace/erp_project/frappe-bench/apps/frappe/frappe/installer.py", line 139, in install_app
    add_module_defs(name)
  File "/home/workspace/erp_project/frappe-bench/apps/frappe/frappe/installer.py", line 335, in add_module_defs
    d.save(ignore_permissions=True)
  File "/home/workspace/erp_project/frappe-bench/apps/frappe/frappe/model/document.py", line 256, in save
    return self._save(*args, **kwargs)
  File "/home/workspace/erp_project/frappe-bench/apps/frappe/frappe/model/document.py", line 279, in _save
    self.insert()
  File "/home/workspace/erp_project/frappe-bench/apps/frappe/frappe/model/document.py", line 233, in insert
    raise e
frappe.exceptions.DuplicateEntryError: (u'Module Def', u'Accounts', IntegrityError(1062, u"Duplicate entry 'Accounts' for key 'PRIMARY'"))

sorry, I am unable to reproduce your issue with the same steps. Can you check your database (or in case it is fresh/empty anyways, purge and create a new one)? What happens if you run bench migrate?

sorry i tried ā€œbench migrateā€ but still the above error shown.

try to bench --site site_name reinstall

4 Likes

Thanks for the help, it worked.

bench --site Site_name install-app erpnext

ImportError: Module import failed for Journal Entry (erpnext.accounts.doctype.journal_entry.journal_entry Error: No module named cache_manager)

first tried ā€˜bench migrateā€™
then bench --site site_name reinstall
but still it shows the below error.

:~/workspace/Artyfetes_Factory/frappe-bench$ bench --site Artyfetes_Factory.com install-app erpnext

Installing erpnext...
Updating DocTypes for erpnext       : [                                        ]Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 94, in <module>
    main()
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 24, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/apps/frappe/frappe/commands/site.py", line 165, in install_app
    _install_app(app, verbose=context.verbose)
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/apps/frappe/frappe/installer.py", line 141, in install_app
    sync_for(name, force=True, sync_everything=True, verbose=verbose, reset_permissions=True)
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/apps/frappe/frappe/model/sync.py", line 45, in sync_for
    reset_permissions=reset_permissions, for_sync=True)
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 58, in import_file_by_path
    ignore_version=ignore_version, reset_permissions=reset_permissions)
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 132, in import_doc
    doc.insert()
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/apps/frappe/frappe/model/document.py", line 248, in insert
    self.run_post_save_methods()
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/apps/frappe/frappe/model/document.py", line 890, in run_post_save_methods
    self.run_method("on_update")
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/apps/frappe/frappe/model/document.py", line 758, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/apps/frappe/frappe/model/document.py", line 1027, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/apps/frappe/frappe/model/document.py", line 1010, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/apps/frappe/frappe/model/document.py", line 752, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py", line 226, in on_update
    self.run_module_method("on_doctype_update")
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py", line 290, in run_module_method
    module = load_doctype_module(self.name, self.module)
  File "/home/indictrans/workspace/Artyfetes_Factory/frappe-bench/apps/frappe/frappe/modules/utils.py", line 187, in load_doctype_module
    raise ImportError('Module import failed for {0} ({1})'.format(doctype, module_name + ' Error: ' + str(e)))
ImportError: Module import failed for Tax Rule (erpnext.accounts.doctype.tax_rule.tax_rule Error: No module named past.builtins)
bench --site site_ts3 install-app erpnext

Installing erpnext...
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 94, in <module>
    main()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 24, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 165, in install_app
    _install_app(app, verbose=context.verbose)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/installer.py", line 139, in install_app
    add_module_defs(name)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/installer.py", line 335, in add_module_defs
    d.save(ignore_permissions=True)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 259, in save
    return self._save(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 282, in _save
    self.insert()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 236, in insert
    raise e
frappe.exceptions.DuplicateEntryError: (u'Module Def', u'Accounts', IntegrityError(1062, u"Duplicate entry 'Accounts' for key 'PRIMARY'"))

Hi @Ahmed_Badawi, @sagarg,

both your cases indicate that the database has remainders from a previous app installation.

Does the error remain if you repeat the exact command?

If it does, I propose to pull a backup, then remove the database, and then create the site fresh.

Thanks.