V12 database restore to v13

any one help for i have a database backup 12.22.0 can possible restore in v13

Hi,

You can easily do it. Create new site on Frappe cloud for Version-13 and while creation of site you will get option to upload the backup. You can upload the version-12 backup and frappecloud will take care for the migration.

Thanks,

Divyesh Mangroliya

but erpnext hosting in AWS or local server then ??

Hi,

If you use the frappecloud, erpnext will be in the cloud. If you don’t want cloud hosting, you can still do that.

If you don’t want cloud hosting, install a new server locally with Latest of Version-13 and restore the backup of version-12 and run the migrate command to migrate the data from version-12 to version-13.

For quick and faster migration, I suggest Frappe Cloud option.

Thanks,

Divyesh Mangroliya

just tried it, but some errors occur when migrating

frappe@ubuntu:~/frappe-bench$ bench --site site1.local --force restore 20240713_053003-erp_ecorex_in-database.sql.gz
MySQL root password:
Restoring Database file…
4.31GiB 0:08:17 [8.87MiB/s] [========================================================================================================================>] 100%
ERROR 1227 (42000) at line 43986: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
*** Scheduler is enabled ***
Site site1.local has been restored
frappe@ubuntu:~/frappe-bench$ ^C
frappe@ubuntu:~/frappe-bench$ bench --site site1.local migrate
Migrating site1.local
Could not find app “mandrill_integration”
frappe@ubuntu:~/frappe-bench$ bench --site site1.local remove-from-installed-apps mandrill_integration
frappe@ubuntu:~/frappe-bench$ bench --site site1.local migrate
Migrating site1.local
Could not find app “erpnext_support”
frappe@ubuntu:~/frappe-bench$ bench --site site1.local remove-from-installed-apps erpnext_support
frappe@ubuntu:~/frappe-bench$ bench --site site1.local migrate
Migrating site1.local
Executing execute:frappe.reload_doc(‘core’, ‘doctype’, ‘doctype_action’, force=True) #2019-09-23 in site1.local (_1bd3e0294da19198)
Success: Done in 0.192s

Executing erpnext.patches.v13_0.update_deferred_settings in site1.local (_1bd3e0294da19198)
Success: Done in 0.336s
Executing erpnext.patches.v13_0.delete_old_sales_reports in site1.local (_1bd3e0294da19198)
Traceback (most recent call last):
File “/usr/lib/python3.6/runpy.py”, line 193, in _run_module_as_main
main”, mod_spec)
File “/usr/lib/python3.6/runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 104, in
main()
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 19, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 829, in call
return self.main(*args, **kwargs)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 782, in main
rv = self.invoke(ctx)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 610, in invoke
return callback(*args, **kwargs)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/decorators.py”, line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/commands/init.py”, line 27, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py”, line 309, in migrate
skip_search_index=skip_search_index
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 91, in execute_patch
frappe.get_attr(patchmodule.split()[0] + “.execute”)()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/patches/v13_0/delete_old_sales_reports.py”, line 15, in execute
frappe.delete_doc(“Report”, report)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 900, in delete_doc
ignore_permissions, flags, ignore_on_trash, ignore_missing, delete_permanently)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/delete_doc.py”, line 105, in delete_doc
check_if_doc_is_linked(doc)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/delete_doc.py”, line 253, in check_if_doc_is_linked
raise_link_exists_exception(doc, linked_doctype, reference_docname)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/delete_doc.py”, line 308, 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 432, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’, is_minimizable=is_minimizable, wide=wide, as_list=as_list)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 411, in msgprint
_raise_exception()
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 365, in _raise_exception
raise raise_exception(msg)
frappe.exceptions.LinkExistsError: Cannot delete or cancel because Report Ordered Items To Be Delivered is linked with Desktop Icon cd4cf1211a
frappe@ubuntu:~/frappe-bench$

Please helps us

@Istaka_IT Try the below steps to solve the error,.

The error you are encountering seems to be related to the delete_old_sales_reports patch in ERPNext. It appears that the patch is trying to delete a report that is linked to other documents, which is causing a LinkExistsError. Here’s how you can address this issue:

  1. Identify the Linked Documents: Find out which documents are linking to the report that is causing the error.
  2. Resolve the Links: Depending on your business logic, you may either need to update or remove these links before the report can be deleted.

Here are the steps you can follow to resolve the issue:

  1. Open the Patch File: Locate the delete_old_sales_reports.py patch file. This is usually found at apps/erpnext/erpnext/patches/v13_0/delete_old_sales_reports.py.
  2. Modify the Patch File to Log the Linked Documents: Update the patch file to log the documents that are linking to the report. This can help you identify the problematic links.

python

Copy code

# Add logging to identify linked documents
import frappe
from frappe.utils import cint

def execute():
    reports = [
        'Sales Analytics',
        'Ordered Items To Be Delivered',
        'Delivered Items To Be Billed',
        'Inactive Customers'
    ]

    for report in reports:
        try:
            # Check if report exists
            if frappe.db.exists("Report", report):
                # Identify linked documents
                linked_docs = frappe.get_all("DocType", filters={"report": report})
                if linked_docs:
                    print(f"Report {report} is linked to: {linked_docs}")
                else:
                    frappe.delete_doc("Report", report)
        except Exception as e:
            print(f"Failed to delete report {report}: {str(e)}")
  1. Run the Migration Again: Run the migration command to execute the modified patch file and log the linked documents.

bash

Copy code

bench --site site1.local migrate
  1. Review the Logs: Check the output logs to identify which documents are linking to the report. The logs will show you the document types and names that are causing the issue.
  2. Update or Remove the Links: Depending on your business requirements, update or remove the links to the reports. You may need to manually update the linked documents to remove the references to the reports.
  3. Retry the Migration: Once the links are resolved, retry the migration.

bash

Copy code

bench --site site1.local migrate

If you prefer to remove the references programmatically, you can add logic in the patch file to update or delete the linked documents before attempting to delete the reports.

By following these steps, you should be able to identify and resolve the linked documents causing the LinkExistsError, allowing the migration to complete successfully.

As per the above instructions, I have followed it but since some error

Executing execute:frappe.reload_doc(“regional”, “doctype”, “e_invoice_settings”) in site1.local (_1bd3e0294da19198)
Success: Done in 0.181s
Executing erpnext.patches.v13_0.check_is_income_tax_component #22-06-2020 in site1.local (_1bd3e0294da19198)
Traceback (most recent call last):
File “/usr/lib/python3.6/runpy.py”, line 193, in _run_module_as_main
main”, mod_spec)
File “/usr/lib/python3.6/runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 104, in
main()
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 19, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 829, in call
return self.main(*args, **kwargs)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 782, in main
rv = self.invoke(ctx)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 610, in invoke
return callback(*args, **kwargs)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/decorators.py”, line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/commands/init.py”, line 27, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py”, line 309, in migrate
skip_search_index=skip_search_index
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 91, in execute_patch
frappe.get_attr(patchmodule.split()[0] + “.execute”)()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/patches/v13_0/check_is_income_tax_component.py”, line 31, in execute
setup(patch=True)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/regional/india/setup.py”, line 17, in setup
setup_company_independent_fixtures(patch=patch)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/regional/india/setup.py”, line 24, in setup_company_independent_fixtures
make_custom_fields()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/regional/india/setup.py”, line 683, in make_custom_fields
create_custom_fields(custom_fields, update=update)
File “/home/frappe/frappe-bench/apps/frappe/frappe/custom/doctype/custom_field/custom_field.py”, line 169, in create_custom_fields
custom_field.save()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 285, in save
return self._save(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 320, in save
self.run_before_save_methods()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 961, in run_before_save_methods
self.run_method(“validate”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 859, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1148, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1131, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 853, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/custom/doctype/custom_field/custom_field.py”, line 58, in validate
frappe.throw(
(“Fieldtype cannot be changed from {0} to {1}”).format(old_fieldtype, self.fieldtype))
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 432, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’, is_minimizable=is_minimizable, wide=wide, as_list=as_list)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 411, in msgprint
_raise_exception()
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 365, in _raise_exception
raise raise_exception(msg)
frappe.exceptions.ValidationError: Fieldtype cannot be changed from Data to Currency

Executing erpnext.patches.v13_0.check_is_income_tax_component #22-06-2020 in site1.local (_1bd3e0294da19198)
Traceback (most recent call last):
File “/usr/lib/python3.6/runpy.py”, line 193, in _run_module_as_main
main”, mod_spec)
File “/usr/lib/python3.6/runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 104, in
main()
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 19, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 829, in call
return self.main(*args, **kwargs)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 782, in main
rv = self.invoke(ctx)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 610, in invoke
return callback(*args, **kwargs)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/decorators.py”, line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/commands/init.py”, line 27, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py”, line 309, in migrate
skip_search_index=skip_search_index
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 91, in execute_patch
frappe.get_attr(patchmodule.split()[0] + “.execute”)()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/patches/v13_0/check_is_income_tax_component.py”, line 31, in execute
setup(patch=True)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/regional/india/setup.py”, line 17, in setup
setup_company_independent_fixtures(patch=patch)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/regional/india/setup.py”, line 24, in setup_company_independent_fixtures
make_custom_fields()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/regional/india/setup.py”, line 683, in make_custom_fields
create_custom_fields(custom_fields, update=update)
File “/home/frappe/frappe-bench/apps/frappe/frappe/custom/doctype/custom_field/custom_field.py”, line 169, in create_custom_fields
custom_field.save()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 285, in save
return self._save(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 337, in _save
self.run_post_save_methods()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 994, in run_post_save_methods
self.run_method(“on_update”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 859, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1148, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1131, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 853, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/custom/doctype/custom_field/custom_field.py”, line 80, in on_update
frappe.db.updatedb(self.dt)
File “/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/database.py”, line 282, in updatedb
db_table.sync()
File “/home/frappe/frappe-bench/apps/frappe/frappe/database/schema.py”, line 40, in sync
self.alter()
File “/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/schema.py”, line 88, in alter
raise e
File “/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/schema.py”, line 75, in alter
frappe.db.sql(query)
File “/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py”, line 151, in sql
self._cursor.execute(query)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/pymysql/cursors.py”, line 148, in execute
result = self._query(query)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/pymysql/cursors.py”, line 310, in _query
conn.query(q)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/pymysql/connections.py”, line 548, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/pymysql/connections.py”, line 775, in _read_query_result
result.read()
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/pymysql/connections.py”, line 1156, in read
first_packet = self.connection._read_packet()
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/pymysql/connections.py”, line 725, in _read_packet
packet.raise_for_error()
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/pymysql/protocol.py”, line 221, in raise_for_error
err.raise_mysql_exception(self._data)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/pymysql/err.py”, line 143, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.OperationalError: (1918, “Encountered illegal value ‘’ when converting to DECIMAL”)


@Istaka_IT  You can try the below steps to solve the error,.

The error you are encountering is due to a validation that prevents changing a custom field's type from "Data" to "Currency". This restriction is in place to maintain data integrity, as changing field types can lead to data inconsistency.

Here’s how to address this issue:

1. **Identify the Field**: Determine which custom field is causing the issue.
2. **Manually Change the Field Type**: If appropriate, manually change the field type via the UI or by modifying the database.
3. **Update the Patch**: Modify the patch to handle this case or skip the custom field update if it already exists.

### Step-by-Step Solution

#### 1. Identify the Custom Field

To identify which custom field is causing the issue, you can print the field details before the validation occurs in the patch file.

python

Copy code

import frappe

def execute():
setup(patch=True)

def setup(patch=False):
setup_company_independent_fixtures(patch=patch)

def setup_company_independent_fixtures(patch=False):
make_custom_fields(patch=patch)

def make_custom_fields(patch=False):
custom_fields = {
# Custom fields definition
}
create_custom_fields(custom_fields, update=patch)

def create_custom_fields(custom_fields, update=False):
for doctype, fields in custom_fields.items():
for fieldname, field in fields.items():
print(f"Checking field: {fieldname} in doctype: {doctype}“)
custom_field = frappe.get_doc({
‘doctype’: ‘Custom Field’,
‘dt’: doctype,
‘fieldname’: fieldname
})
if update:
if frappe.db.exists(‘Custom Field’, {‘dt’: doctype, ‘fieldname’: fieldname}):
existing_field = frappe.get_doc(‘Custom Field’, {‘dt’: doctype, ‘fieldname’: fieldname})
if existing_field.fieldtype != field[‘fieldtype’]:
print(f"Fieldtype conflict: {existing_field.fieldtype} → {field[‘fieldtype’]} for field {fieldname}”)
continue
custom_field.update(field)
custom_field.save()


#### 2. Run the Migration Again

Run the migration command to see which field is causing the issue.

bash

Copy code

bench --site site1.local migrate


#### 3. Resolve the Field Type Conflict

After identifying the field, you have a few options:

* **Manually Update the Field Type**: Change the field type from "Data" to "Currency" via the UI or using a custom script.
* **Modify the Patch to Skip the Field**: Update the patch to skip updating the field type if it conflicts.

#### Manual Field Update via UI

1. Go to the "Custom Field" list.
2. Find the custom field that needs to be updated.
3. Change the field type from "Data" to "Currency".

#### Modify the Patch to Skip the Field

Update the patch to skip updating the custom field if it conflicts:

python

Copy code

def create_custom_fields(custom_fields, update=False):
for doctype, fields in custom_fields.items():
for fieldname, field in fields.items():
if frappe.db.exists(‘Custom Field’, {‘dt’: doctype, ‘fieldname’: fieldname}):
existing_field = frappe.get_doc(‘Custom Field’, {‘dt’: doctype, ‘fieldname’: fieldname})
if existing_field.fieldtype != field[‘fieldtype’]:
print(f"Skipping field {fieldname} due to fieldtype conflict: {existing_field.fieldtype} → {field[‘fieldtype’]}")
continue
custom_field = frappe.get_doc({
‘doctype’: ‘Custom Field’,
‘dt’: doctype,
‘fieldname’: fieldname
})
custom_field.update(field)
custom_field.save()


#### 4. Retry the Migration

Once the conflicts are resolved, retry the migration.

bash

Copy code

bench --site site1.local migrate


By following these steps, you should be able to identify and resolve the field type conflict, allowing the migration to complete successfully.

Great Sir,

I have followed it step by step, and it’s working fine, I think the below error is final
Please see this error while Updating DocTypes

Updating DocTypes for frappe : [========================================] 100%
Updating DocTypes for erpnext : [= ] 2%

There was an issue while migrating the DocType: Purchase Invoice

Traceback (most recent call last):
File “/usr/lib/python3.6/runpy.py”, line 193, in _run_module_as_main
main”, mod_spec)
File “/usr/lib/python3.6/runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 104, in
main()
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 19, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 829, in call
return self.main(*args, **kwargs)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 782, in main
rv = self.invoke(ctx)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 610, in invoke
return callback(*args, **kwargs)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/decorators.py”, line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/commands/init.py”, line 27, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py”, line 309, in migrate
skip_search_index=skip_search_index
File “/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py”, line 70, in migrate
frappe.model.sync.sync_all(verbose=verbose)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/sync.py”, line 19, in sync_all
sync_for(app, force, verbose=verbose, reset_permissions=reset_permissions)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/sync.py”, line 70, in sync_for
reset_permissions=reset_permissions, for_sync=True)
File “/home/frappe/frappe-bench/apps/frappe/frappe/modules/import_file.py”, line 70, in import_file_by_path
ignore_version=ignore_version, reset_permissions=reset_permissions)
File “/home/frappe/frappe-bench/apps/frappe/frappe/modules/import_file.py”, line 152, in import_doc
doc.insert()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 268, in insert
self.run_post_save_methods()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 994, in run_post_save_methods
self.run_method(“on_update”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 859, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1148, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1131, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 853, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py”, line 302, in on_update
raise e
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py”, line 299, in on_update
frappe.db.updatedb(self.name, Meta(self))
File “/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/database.py”, line 282, in updatedb
db_table.sync()
File “/home/frappe/frappe-bench/apps/frappe/frappe/database/schema.py”, line 40, in sync
self.alter()
File “/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/schema.py”, line 88, in alter
raise e
File “/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/schema.py”, line 75, in alter
frappe.db.sql(query)
File “/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py”, line 151, in sql
self._cursor.execute(query)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/pymysql/cursors.py”, line 148, in execute
result = self._query(query)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/pymysql/cursors.py”, line 310, in _query
conn.query(q)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/pymysql/connections.py”, line 548, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/pymysql/connections.py”, line 775, in _read_query_result
result.read()
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/pymysql/connections.py”, line 1156, in read
first_packet = self.connection._read_packet()
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/pymysql/connections.py”, line 725, in _read_packet
packet.raise_for_error()
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/pymysql/protocol.py”, line 221, in raise_for_error
err.raise_mysql_exception(self._data)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/pymysql/err.py”, line 143, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.OperationalError: (1918, “Encountered illegal value ‘’ when converting to DECIMAL”)

@Istaka_IT Follow the below steps please,.

The error you’re encountering during the migration process for the Purchase Invoice Doctype in Frappe Version 15 is caused by an illegal value being encountered when converting to a DECIMAL type in the database. This typically occurs when a field that is expected to be a decimal contains an invalid value (e.g., an empty string).

Here are some steps to troubleshoot and resolve this issue:

  1. Identify the Field Causing the Issue:

    • The error indicates that a field expected to contain a decimal value has an illegal value (an empty string in this case). You need to identify which field in the Purchase Invoice Doctype is causing this issue.
  2. Check for Empty Strings in Decimal Fields:

    • You can run a query to check for empty strings in fields that are expected to be decimal in the Purchase Invoice Doctype.
  3. Update or Cleanse the Data:

    • Once you identify the problematic fields, you need to update these fields to have valid decimal values or NULL values instead of empty strings.
  4. Modify Doctype Definition if Necessary:

    • Ensure that the Doctype definition correctly handles empty or invalid values for decimal fields.

Detailed Steps

  1. Identify Decimal Fields in Purchase Invoice Doctype:

    • Go to the Purchase Invoice Doctype definition in Frappe and list out all fields that are of type Float or Currency.
  2. Run SQL Queries to Find Invalid Values:

    • Access your MariaDB database and run queries to find any empty strings in these fields.
    USE your_database_name;
    
    -- Example query to find invalid values in a specific field
    SELECT name, field_name FROM `tabPurchase Invoice` WHERE field_name = '';
    

    Replace field_name with the actual name of the decimal field.

  3. Update Invalid Values:

    • Update these fields to have valid decimal values or NULL instead of empty strings.
    -- Example query to update invalid values
    UPDATE `tabPurchase Invoice` SET field_name = NULL WHERE field_name = '';
    

    Again, replace field_name with the actual name of the decimal field.

  4. Run Bench Migrate Again:

    • After updating the invalid values, run the migration command again.
    bench migrate
    

Example Script to Handle All Decimal Fields

If there are multiple fields to check, you can create a script to automate this process.

import frappe

def update_invalid_decimal_fields():
    # List of decimal fields in Purchase Invoice Doctype
    decimal_fields = ['field1', 'field2', 'field3']  # Replace with actual field names

    for field in decimal_fields:
        frappe.db.sql(f"""
            UPDATE `tabPurchase Invoice`
            SET `{field}` = NULL
            WHERE `{field}` = '';
        """)

if __name__ == "__main__":
    frappe.connect()
    update_invalid_decimal_fields()
    frappe.db.commit()
    frappe.destroy()

Run this script to update invalid values in all specified decimal fields.

By following these steps, you should be able to resolve the issue and successfully migrate your Purchase Invoice Doctype.