Error while deleteting any data

Traceback (most recent call last):
  File "/home/vhrs/frappe-bench/apps/frappe/frappe/", line 55, in application
    response = frappe.handler.handle()
  File "/home/vhrs/frappe-bench/apps/frappe/frappe/", line 19, in handle
  File "/home/vhrs/frappe-bench/apps/frappe/frappe/", line 36, in execute_cmd
    ret =, **frappe.form_dict)
  File "/home/vhrs/frappe-bench/apps/frappe/frappe/", line 854, in call
    return fn(*args, **newargs)
  File "/home/vhrs/frappe-bench/apps/frappe/frappe/desk/", line 134, in delete_items
    frappe.delete_doc(doctype, d)
  File "/home/vhrs/frappe-bench/apps/frappe/frappe/", line 591, in delete_doc
    ignore_permissions, flags)
  File "/home/vhrs/frappe-bench/apps/frappe/frappe/model/", line 72, in delete_doc
  File "/home/vhrs/frappe-bench/apps/frappe/frappe/model/", line 601, in run_method
    return Document.hook(fn)(self, *args, **kwargs)
  File "/home/vhrs/frappe-bench/apps/frappe/frappe/model/", line 765, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/vhrs/frappe-bench/apps/frappe/frappe/model/", line 748, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/vhrs/frappe-bench/apps/frappe/frappe/model/", line 595, in 
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/vhrs/frappe-bench/apps/erpnext/erpnext/setup/doctype/company/", line 198, in on_trash
    where exists(select name from tabBudget where name=b.parent and company = %s)""",
  File "/home/vhrs/frappe-bench/apps/frappe/frappe/", line 136, in sql
    self._cursor.execute(query, values)
  File "/home/vhrs/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/", line 205, in execute
    self.errorhandler(self, exc, value)
  File "/home/vhrs/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
ProgrammingError: (1064, "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 'b\n\t\t\t\twhere exists(select name from tabBudget where name=b.parent and company = ' at line 1")

@nabinhait seems related to budget

I never tried related to budget but it is throwing error

Pushed the fix, please update and check.