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/document.py”, line 1048, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1031, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 766, 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 238, in on_update
self.delete_duplicate_custom_fields()
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py”, line 284, in delete_duplicate_custom_fields
‘’‘.format(’%s’, ‘, ‘.join([’%s’] * len(fields))), tuple([self.name] + fields), as_dict=True)
File “/home/frappe/frappe-bench/apps/frappe/frappe/database.py”, line 199, in sql
self._cursor.execute(query, values)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.py”, line 170, in execute
result = self._query(query)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.py”, line 328, in _query
conn.query(q)
File “/home/frappe/frappe-bench/env/local/lib/python2.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/local/lib/python2.7/site-packages/pymysql/connections.py”, line 732, in _read_query_result
result.read()
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py”, line 1075, in read
first_packet = self.connection._read_packet()
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py”, line 684, in _read_packet
packet.check_error()
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/protocol.py”, line 220, in check_error
err.raise_mysql_exception(self._data)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/err.py”, 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.

Try

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(self.name) and frappe.db.table_exists("Custom Field")):
                    return
            fields = [d.fieldname for d in self.fields if d.fieldtype in type_map]
            frappe.db.sql('''delete from
                            `tabCustom Field`
                    where
                             dt = {0} and fieldname in ({1})
            '''.format('%s', ', '.join(['%s'] * len(fields))), tuple([self.name] + 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`
where
   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