Error regarding migrate on custom app

Hi, I’m running into problems when trying to migrate an erpnext instance where I’ve previously installed a custom app.

The traceback log is given below:

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 "/opt/bench/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 97, in <module>
    main()
  File "/opt/bench/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/opt/bench/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/opt/bench/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/opt/bench/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 "/opt/bench/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 "/opt/bench/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/bench/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/opt/bench/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 "/opt/bench/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 25, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/opt/bench/frappe-bench/apps/frappe/frappe/commands/site.py", line 228, in migrate
    migrate(context.verbose, rebuild_website=rebuild_website)
  File "/opt/bench/frappe-bench/apps/frappe/frappe/migrate.py", line 42, in migrate
    sync_fixtures()
  File "/opt/bench/frappe-bench/apps/frappe/frappe/utils/fixtures.py", line 24, in sync_fixtures
    ignore_links=True, overwrite=True)
  File "/opt/bench/frappe-bench/apps/frappe/frappe/core/doctype/data_import/data_import.py", line 56, in import_doc
    frappe.modules.import_file.import_file_by_path(f, data_import=True, force=True, pre_process=pre_process, reset_permissions=True)
  File "/opt/bench/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 65, in import_file_by_path
    ignore_version=ignore_version, reset_permissions=reset_permissions)
  File "/opt/bench/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 133, in import_doc
    doc.insert()
  File "/opt/bench/frappe-bench/apps/frappe/frappe/model/document.py", line 236, in insert
    raise e
frappe.exceptions.DuplicateEntryError: (u'Custom Field', u'Program Enrollment-_party', IntegrityError(1062, u"Duplicate entry 'Program Enrollment-_party' for key 'PRIMARY'"))

Can anyone tell me what’s wrong with my app? It seems the migrate fails when it tries to sync the fixtures.

Hello @iamtribulation

The error happens because your current site already has the custom field which can be found in Custom Field doctype. If you wish to fix, try to modify your fixtures under fixtures/custom_field.json and then scrape out the field that you are having trouble with.

Regards,

Ivan

Hey @iRaySpace

I’m aware of how to get by it. It seems removing the problematic field from Custom Field List also helps making the migrate successful.

My concern here was if it were possible to do it without any sort of meddling on a production server(aside from installation of course). My scenario here is that the server won’t always be there giving me write access. So, in order to make sure the customization doesn’t come in the way of updates and migrates, I’d like the custom app to function right out of the box, with no more than a bench install-app. Is something like that possible, or will I be needing an after-install script to remove fixtures altogether?

Hello @iamtribulation

This is kind of an app development implementation idea, but would like to share that you can get ideas from ERPNext with your installation. One of the things that you can do so, which probably you can find in ERPNext is that they implement patches scripts which you probably notice.

With this in mind, I have noticed that ERPNext implements the creation of custom fields using this kind of method. You simply put your scripts under patches.txt and have a script that will create your custom fields required for the app.

View this snippets right here. This might help you.

patches.txt

create_custom_fields_for_india_specific_fields.py

Regards,

Ivan