Migrating from v13 to fresh v14 installation, bench migrate command throws up an error where it expects a doctype present in HRMS

In my custom app, I have certain customizations (custom JS as well as custom fields) to modules which are now moved to HRMS app in v14 of ERPNext.

In my app, I have accordingly modified the dotted paths in my code to accommodate this change.

While creating a fresh installation of ERPNext v14 on local(as well as Frappe Cloud) instance I followed through as below.

  1. Install apps in the following order : Frappe, Payments, Erpnext, HRMS
  2. Ensured that the site booted up without any issues.
  3. Installed my custom app without any issues. (installed custom app at the end because of dependencies with HRMS and ERPNext)
  4. Attempt to restore the database from a v13 instance.

This is where I faced my first issue of which the stack trace is below :

Linking stack trace here to due to forum limitations.

In the end it did say that the site was restored with files, so I tried to boot up the site. I couldn’t get any further than the login page so I ran a bench migrate

This resulted in the second stack trace which seems to show that some doctype is missing but clearly the app was installed.

Migrating site1.local

Updating DocTypes for frappe        : [========================================] 100%
Updating DocTypes for erpnext       : [========================================] 100%
Updating DocTypes for abs_india     : [========================================] 100%
Updating DocTypes for wiki          : [========================================] 100%

Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/erp/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 109, in <module>
    main()
  File "/home/erp/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name="bench")
  File "/home/erp/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/erp/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/erp/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/erp/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/erp/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/erp/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/erp/frappe-bench/env/lib/python3.10/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/erp/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 29, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/erp/frappe-bench/apps/frappe/frappe/commands/site.py", line 523, in migrate
    SiteMigration(
  File "/home/erp/frappe-bench/apps/frappe/frappe/migrate.py", line 174, in run
    self.post_schema_updates()
  File "/home/erp/frappe-bench/apps/frappe/frappe/migrate.py", line 40, in wrapper
    ret = method(*args, **kwargs)
  File "/home/erp/frappe-bench/apps/frappe/frappe/migrate.py", line 131, in post_schema_updates
    sync_fixtures()
  File "/home/erp/frappe-bench/apps/frappe/frappe/utils/fixtures.py", line 22, in sync_fixtures
    import_doc(fixtures_path)
  File "/home/erp/frappe-bench/apps/frappe/frappe/core/doctype/data_import/data_import.py", line 216, in import_doc
    import_file_by_path(
  File "/home/erp/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 145, in import_file_by_path
    import_doc(
  File "/home/erp/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 242, in import_doc
    doc.insert()
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/document.py", line 254, in insert
    self.run_before_save_methods()
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/document.py", line 1055, in run_before_save_methods
    self.run_method("validate")
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/document.py", line 927, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/document.py", line 1267, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/document.py", line 1249, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/document.py", line 924, in fn
    return method_object(*args, **kwargs)
  File "/home/erp/frappe-bench/apps/frappe/frappe/custom/doctype/custom_field/custom_field.py", line 48, in validate
    meta = frappe.get_meta(self.dt, cached=False)
  File "/home/erp/frappe-bench/apps/frappe/frappe/__init__.py", line 1210, in get_meta
    return frappe.model.meta.get_meta(doctype, cached=cached)
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/meta.py", line 57, in get_meta
    return load_meta(doctype)
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/meta.py", line 61, in load_meta
    return Meta(doctype)
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/meta.py", line 113, in __init__
    super().__init__("DocType", doctype)
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/document.py", line 105, in __init__
    self.load_from_db()
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/meta.py", line 118, in load_from_db
    super().load_from_db()
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/document.py", line 147, in load_from_db
    frappe.throw(
  File "/home/erp/frappe-bench/apps/frappe/frappe/__init__.py", line 523, in throw
    msgprint(
  File "/home/erp/frappe-bench/apps/frappe/frappe/__init__.py", line 491, in msgprint
    _raise_exception()
  File "/home/erp/frappe-bench/apps/frappe/frappe/__init__.py", line 443, in _raise_exception
    raise raise_exception(msg)
frappe.exceptions.DoesNotExistError: DocType Employee Grade not found

The only way I could solve this is to install HRMS app again,

bench install-app hrms

The site is now fully functional with all the data available as expected.

But this doesnt seem like the correct solution to this.

It feels like somewhere the updating of HRMS doctype is occurring out of order and attempting to update it again through the install-app command seems to fix it.

Is there anyway I can control the migration order to prevent this issue.

1 Like