Erpnext: Migrate from 12 to 13 fails

Created on 10 Jun 2020  Β·  12Comments  Β·  Source: frappe/erpnext

Reproduce

Manually switch frappe and erpnext to version-13-beta branch because bench switch-to-branch doesn't actually switch the branch.

bench use site1.local
bench reinstall
bench --force restore /path/to/backup_from_version-12.sql.gz
bench migrate

Error

Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 97, 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/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/frappe/frappe-bench/env/lib/python3.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/lib/python3.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/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python3.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 25, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 242, in migrate
    migrate(context.verbose, rebuild_website=rebuild_website, skip_failing=skip_failing)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py", line 67, in migrate
    frappe.modules.patch_handler.run_all(skip_failing)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 41, in run_all
    run_patch(patch)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 30, in run_patch
    if not run_single(patchmodule = patch):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 71, in run_single
    return execute_patch(patchmodule, method, methodargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 89, in execute_patch
    exec(patchmodule.split("execute:")[1],globals())
  File "<string>", line 1, in <module>
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 820, in delete_doc_if_exists
    delete_doc(doctype, name, force=force)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 815, in delete_doc
    ignore_permissions, flags, ignore_on_trash, ignore_missing)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/delete_doc.py", line 105, in delete_doc
    delete_from_table(doctype, name, ignore_doctypes, doc)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/delete_doc.py", line 191, in delete_from_table
    frappe.db.sql("delete from `tab%s` where parenttype=%s and parent = %s" % (t, '%s', '%s'), (doctype, name))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 158, in sql
    self._cursor.execute(query, values)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/cursors.py", line 170, in execute
    result = self._query(query)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/cursors.py", line 328, in _query
    conn.query(q)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 517, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 732, in _read_query_result
    result.read()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 1075, in read
    first_packet = self.connection._read_packet()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 684, in _read_packet
    packet.check_error()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/protocol.py", line 220, in check_error
    err.raise_mysql_exception(self._data)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.ProgrammingError: (1146, "Table '_1xxxxxxxxxxxxxxx8.tabNumber Card Link' doesn't exist")

Most helpful comment

Hello,

It's work when I delete first 'Accounting' record of 'Desk Page' DocType manually or modifying code in patch.txt file.

patch.txt will look like this after modify:

...
execute:frappe.delete_doc_if_exists('Desk Page', 'Accounting')
execute:frappe.delete_doc_if_exists('Dashboard', 'Accounts')
...

then please try bench migrate finally and it will work.

Thank you.

All 12 comments

bench migrate --skip-failing #works
bench update --patch
Backing up sites...
Patching sites...
Migrating site1.local
Executing execute:frappe.delete_doc_if_exists('Dashboard', 'Accounts') in site1.local (_1bd3e0294da19198)
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)   
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals) 
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 97, 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/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/frappe/frappe-bench/env/lib/python3.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/lib/python3.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/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python3.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 25, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 242, in migrate
    migrate(context.verbose, rebuild_website=rebuild_website, skip_failing=skip_failing)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py", line 67, in migrate
    frappe.modules.patch_handler.run_all(skip_failing)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 41, in run_all
    run_patch(patch)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 30, in run_patch
    if not run_single(patchmodule = patch):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 71, in run_single
    return execute_patch(patchmodule, method, methodargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 89, in execute_patch
    exec(patchmodule.split("execute:")[1],globals())
  File "<string>", line 1, in <module>
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 820, in delete_doc_if_exists
    delete_doc(doctype, name, force=force)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 815, in delete_doc
    ignore_permissions, flags, ignore_on_trash, ignore_missing)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/delete_doc.py", line 102, in delete_doc
    check_if_doc_is_dynamically_linked(doc)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/delete_doc.py", line 292, in check_if_doc_is_dynamically_linked
    raise_link_exists_exception(doc, reference_doctype, reference_docname, at_position)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/delete_doc.py", line 303, in raise_link_exists_exception
    .format(doc.doctype, doc_link, reference_doctype, reference_link, row), frappe.LinkExistsError)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 397, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator='red', is_minimizable=is_minimizable)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 376, in msgprint
    _raise_exception()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 327, in _raise_exception
    raise raise_exception(msg)
frappe.exceptions.LinkExistsError: Cannot delete or cancel because Dashboard <a href="#Form/Dashboard/Accounts">Accounts</a> is linked with Desk Page <a href="#Form/Desk Page/Accounting">Accounting</a> at Row: 4

Same error here when to uninstall erpnext

Same issue here, I moved a v12 backup to a working v13 bench and got
pymysql.err.ProgrammingError: (1146, "Table '_1xxxxxxxxxxxxxxx8.tabNumber Card Link' doesn't exist")

Able to go past this thanks to @barredterra

bench migrate --skip-failing

but you keep having to skip failing because of
frappe.exceptions.LinkExistsError: Cannot delete or cancel because Dashboard <a href="#Form/Dashboard/Accounts">Accounts</a> is linked with Desk Page <a href="#Form/Desk Page/Accounting">Accounting</a> at Row: 9

https://github.com/frappe/erpnext/blob/ccd554c19c7dfa568c443b4120adc3faf0aae5eb/erpnext/patches.txt#L693-L694

I guess the problem is at this point.

Maybe we can remove the first line (reload_doctype) so that it will not check or Number Card Link?

Or, instead, reload Number Card Link as well execute:frappe.reload_doctype('Number Card Link')?

@dawoodjee could you check if any of the above works?

Same error here when trying to update from v12 to v13.

Hey all,
Did you manage to sort out that issue. I am facing the same issue.
@barredterra , in bench console,
first line: execute:frappe.reload_doctype('Dashboard') works
frappe.delete_doc_if_exists('Dashboard', 'Accounts') crashed.

So we could just removed that line in patch.txt. But then we can't update anymore.

I have tried bench migrate --skip-failing
bench build
bench restart

All 3 commands works, but the sites are still off (in maintenance mode)
so I just edited the file
nano common_site_config.json

and put "maintenance_mode" to 0

Hello,

It's work when I delete first 'Accounting' record of 'Desk Page' DocType manually or modifying code in patch.txt file.

patch.txt will look like this after modify:

...
execute:frappe.delete_doc_if_exists('Desk Page', 'Accounting')
execute:frappe.delete_doc_if_exists('Dashboard', 'Accounts')
...

then please try bench migrate finally and it will work.

Thank you.

@waiminn will there still be a desk page for Accounting afterwards? Would be a pity to lose it just for the migration to work.
α€›α€”α€Ία€€α€―α€”α€Ία€€α€­α€―α€™α€„α€Ία€Ήα€‚α€œα€¬α€•α€«

@barredterra In my case, a desk page for 'Accounting' regenerated after running bench migrate. Thanks.
α€›α€”α€Ία€€α€―α€”α€Ία€™α€Ύ α€€α€»α€±α€Έα€‡α€°α€Έα€α€„α€Ία€•α€«α€α€šα€Ί

I tried to reproduce this error. The following works fine for me (no error):

  1. Create a new site (version-12) and complete the setup wizard
  2. Switch to version-13-beta
  3. Run the patches

Here are the commands I used:

lsb_release -a # Ubuntu 18.04.5 LTS
bench --version # 5.0.0
bench init --frappe-branch version-12 migration-bench
cd migration-bench
bench get-app --branch version-12 erpnext
bench new-site --install-app erpnext migration.local
bench start
# complete setup wizard
bench switch-to-branch --upgrade version-13-beta frappe erpnext
bench update --patch
bench setup requirements
bench build
bench --site migration.local clear-cache

However, trying to migrate a backup from our production instance, I get another error described here: https://github.com/frappe/frappe/issues/12132

Ok, it seems just removing the Accounts row from tabDashboard solves the issue

  • Simply login to mysql
  • Use the specific database, then:

delete from tabDashboard where name='Accounts';

Was this page helpful?
0 / 5 - 0 ratings

Related issues

neilLasrado picture neilLasrado  Β·  4Comments

royalhospital picture royalhospital  Β·  4Comments

cradford picture cradford  Β·  4Comments

heyakyra picture heyakyra  Β·  4Comments

Fredoluka picture Fredoluka  Β·  3Comments