Migration Error V12 to v13

Hi,

I was trying to move a backup from V12 (on Ubuntu 180.04) to a new installation of V13 (on Ubuntu 20.04). The restore went through without any problems, but I get this error when trying to do a “bench --site site1.local migrate”. Can someone help me with this error please ? Thanks.

:~/frappe-bench$ bench --site site1.local migrate
WARN: bench is installed in editable mode!

This is not the recommended mode of installation for production. Instead, install the package from PyPI with: pip install frappe-bench

Migrating site1.local
Executing erpnext.patches.v13_0.set_company_in_leave_ledger_entry in site1.local (_1bd3e0294da19198)
Traceback (most recent call last):
File “/usr/lib/python3.8/runpy.py”, line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File “/usr/lib/python3.8/runpy.py”, line 87, in _run_code
exec(code, run_globals)
File “/home/erp-admin/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 104, in
main()
File “/home/erp-admin/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 19, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/erp-admin/frappe-bench/env/lib/python3.8/site-packages/click/core.py”, line 829, in call
return self.main(*args, **kwargs)
File “/home/erp-admin/frappe-bench/env/lib/python3.8/site-packages/click/core.py”, line 782, in main
rv = self.invoke(ctx)
File “/home/erp-admin/frappe-bench/env/lib/python3.8/site-packages/click/core.py”, line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/erp-admin/frappe-bench/env/lib/python3.8/site-packages/click/core.py”, line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/erp-admin/frappe-bench/env/lib/python3.8/site-packages/click/core.py”, line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/erp-admin/frappe-bench/env/lib/python3.8/site-packages/click/core.py”, line 610, in invoke
return callback(*args, **kwargs)
File “/home/erp-admin/frappe-bench/env/lib/python3.8/site-packages/click/decorators.py”, line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/erp-admin/frappe-bench/apps/frappe/frappe/commands/init.py”, line 27, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/erp-admin/frappe-bench/apps/frappe/frappe/commands/site.py”, line 306, in migrate
migrate(
File “/home/erp-admin/frappe-bench/apps/frappe/frappe/migrate.py”, line 67, in migrate
frappe.modules.patch_handler.run_all(skip_failing)
File “/home/erp-admin/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 41, in run_all
run_patch(patch)
File “/home/erp-admin/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 30, in run_patch
if not run_single(patchmodule = patch):
File “/home/erp-admin/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 71, in run_single
return execute_patch(patchmodule, method, methodargs)
File “/home/erp-admin/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 91, in execute_patch
frappe.get_attr(patchmodule.split()[0] + “.execute”)()
File “/home/erp-admin/frappe-bench/apps/erpnext/erpnext/patches/v13_0/set_company_in_leave_ledger_entry.py”, line 6, in execute
frappe.db.sql(“”“update tabLeave Ledger Entry as lle set company = (select company from tabEmployee where employee = lle.employee)”“”)
File “/home/erp-admin/frappe-bench/apps/frappe/frappe/database/database.py”, line 153, in sql
self._cursor.execute(query)
File “/home/erp-admin/frappe-bench/env/lib/python3.8/site-packages/pymysql/cursors.py”, line 148, in execute
result = self._query(query)
File “/home/erp-admin/frappe-bench/env/lib/python3.8/site-packages/pymysql/cursors.py”, line 310, in _query
conn.query(q)
File “/home/erp-admin/frappe-bench/env/lib/python3.8/site-packages/pymysql/connections.py”, line 548, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File “/home/erp-admin/frappe-bench/env/lib/python3.8/site-packages/pymysql/connections.py”, line 775, in _read_query_result
result.read()
File “/home/erp-admin/frappe-bench/env/lib/python3.8/site-packages/pymysql/connections.py”, line 1156, in read
first_packet = self.connection._read_packet()
File “/home/erp-admin/frappe-bench/env/lib/python3.8/site-packages/pymysql/connections.py”, line 725, in _read_packet
packet.raise_for_error()
File “/home/erp-admin/frappe-bench/env/lib/python3.8/site-packages/pymysql/protocol.py”, line 221, in raise_for_error
err.raise_mysql_exception(self._data)
File “/home/erp-admin/frappe-bench/env/lib/python3.8/site-packages/pymysql/err.py”, line 143, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.OperationalError: (1242, ‘Subquery returns more than 1 row’)

Hi,

Any help on this is really appreciated. I’m still getting this same error. Not able to restore a V12 backup to V13.

Thanks.

On the new installation where you able to get bench up and running with V12 before migrating to V13 ?

Yes, I created a dummy company on V13, logged into it through the web and confirmed and then attempted to restore.

I’ve done a migration from V12 to V13 yesterday and didn’t get that error.

This probably isn’t a good idea but you could try removing that patch so it gets skipped?

Any idea how to remove the patch?

I found the patch under …/frappe-bench/apps/erpnext/erpnext/patches/v13_0/… and I tried removing it, but during the bench update/migrate it keeps throwing the same error.

I believe you should remove it from here: erpnext/patches.txt at develop · frappe/erpnext · GitHub

Hi,
Thanks. I managed to ship that patch through the patches.txt file. Now I can run “bench update --patch” and “bench migrate” without an issue.

However when I try to run “bench update” I get an error about the change that I have done, and either I have to remove the #comment in the patches.txt file or run a “bench update --reset” which throws out the initial error. Thanks for the help.