Error installing erpnext app in new site

I already have 3 ErpNext v11.1.46 sites running which were setup a month ago with multi-tenant setup.

Now i am trying to install in another new site its giving below error. Please help.

File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 1048, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 1031, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 766, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/doctype/”, line 238, in on_update
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/doctype/”, line 284, in delete_duplicate_custom_fields
‘’‘.format(’%s’, ‘, ‘.join([’%s’] * len(fields))), tuple([] + fields), as_dict=True)
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 199, in sql
self._cursor.execute(query, values)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/”, line 170, in execute
result = self._query(query)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/”, line 328, in _query
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/”, line 517, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/”, line 732, in _read_query_result
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/”, line 1075, in read
first_packet = self.connection._read_packet()
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/”, line 684, in _read_packet
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/”, line 220, in check_error
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/”, line 109, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.ProgrammingError: (1064, u"You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘)’ at line 4")

Looks like there is an error caused by a custom mod/app. Maybe uninstall that, add the site, and then reinstall it

There is no custom app installed. Only few custom fields in the running ErpNext site.


sudo bench --site all migrate
bench update --reset

I just tries
sudo bench --site all migrate

It gave me the very same error

def delete_duplicate_custom_fields(self):
            if not (frappe.db.table_exists( and frappe.db.table_exists("Custom Field")):
            fields = [d.fieldname for d in self.fields if d.fieldtype in type_map]
            frappe.db.sql('''delete from
                            `tabCustom Field`
                             dt = {0} and fieldname in ({1})
            '''.format('%s', ', '.join(['%s'] * len(fields))), tuple([] + fields), as_dict=True)

This is the query which is giving error. How do i find which database and which duplicate column it is trying to delete?

Seems like it is here

Ya… I have 4 ErpNext databases and have checked all, it only has the fields added by the ErpNext script there is none i have added by myself… Not able to find which one is causing the issue

Found the issue after enabling the SQL Logs

delete from
   `tabCustom Field`
   dt = 'Org' and fieldname in ()

This is the query causing the issue it seems.

As i have multiple sites running in the same instance, in one of the site i created a custom DocType “Org” which is not present in other sites of of same ERPNext app.

I think the new site installation and bench migrate is trying to delete this custom field.

Now i am wondering how to solve this without disturbing the existing sites.

1 Like