pymysql.err.OperationalError: (1054, "Unknown column 'incoming_rate' in 'field list'")

I keep getting the following error when I try to create a purchase order from a sales order and try to save the purchase.

I have updated and migrated successfully but the error remains.

My site is hosted on frappe cloud.

Any suggestions would be appreciated.

Installed Apps
ERPNext: v13.40.2 (HEAD)

Frappe Framework: v13.41.7 (HEAD)

Traceback (most recent call last):
File “apps/frappe/frappe/”, line 69, in application
response = frappe.api.handle()
File “apps/frappe/frappe/”, line 55, in handle
return frappe.handler.handle()
File “apps/frappe/frappe/”, line 38, in handle
data = execute_cmd(cmd)
File “apps/frappe/frappe/”, line 76, in execute_cmd
return, **frappe.form_dict)
File “apps/frappe/frappe/”, line 1457, in call
return fn(*args, **newargs)
File “apps/frappe/frappe/desk/form/”, line 24, in savedocs
File “apps/frappe/frappe/model/”, line 310, in save
return self._save(*args, **kwargs)
File “apps/frappe/frappe/model/”, line 332, in _save
return self.insert()
File “apps/frappe/frappe/model/”, line 261, in insert
File “apps/frappe/frappe/model/”, line 1052, in run_before_save_methods
File “apps/frappe/frappe/model/”, line 941, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “apps/frappe/frappe/model/”, line 1261, in composer
return composed(self, method, *args, **kwargs)
File “apps/frappe/frappe/model/”, line 1243, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “apps/frappe/frappe/model/”, line 938, in fn
return method_object(*args, **kwargs)
File “apps/erpnext/erpnext/buying/doctype/purchase_order/”, line 54, in validate
super(PurchaseOrder, self).validate()
File “apps/erpnext/erpnext/controllers/”, line 33, in validate
super(BuyingController, self).validate()
File “apps/erpnext/erpnext/controllers/”, line 42, in validate
super(StockController, self).validate()
File “apps/erpnext/erpnext/controllers/”, line 155, in validate
File “apps/erpnext/erpnext/controllers/”, line 307, in set_incoming_rate
frappe.db.get_value(ref_doctype, d.get(frappe.scrub(ref_doctype)), field)
File “apps/frappe/frappe/database/”, line 469, in get_value
File “apps/frappe/frappe/database/”, line 540, in get_values
File “apps/frappe/frappe/database/”, line 739, in _get_values_from_table
File “apps/frappe/frappe/database/”, line 174, in sql
self._cursor.execute(query, values)
File “env/lib/python3.7/site-packages/pymysql/”, line 148, in execute
result = self._query(query)
File “env/lib/python3.7/site-packages/pymysql/”, line 310, in _query
File “env/lib/python3.7/site-packages/pymysql/”, line 548, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File “env/lib/python3.7/site-packages/pymysql/”, line 775, in _read_query_result
File “env/lib/python3.7/site-packages/pymysql/”, line 1156, in read
first_packet = self.connection._read_packet()
File “env/lib/python3.7/site-packages/pymysql/”, line 725, in _read_packet
File “env/lib/python3.7/site-packages/pymysql/”, line 221, in raise_for_error
File “env/lib/python3.7/site-packages/pymysql/”, line 143, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.OperationalError: (1054, “Unknown column ‘incoming_rate’ in ‘field list’”)

Anyone able to help?

I’m having the same error too. Manually create the PO and link it to Sales order with the same item and same supplier has no error.

Looking for any suggestion. Thanks.

I notice the error is because of the particular supplier that I issue PO is actually an Internal Supplier…

I have noticed the same issue occurs for me on when the PO is made against an internal supplier.

I am no expert and do not know how all the various code files interact, but I think I have isolated the issue to the following function in

def set_incoming_rate(self):
	if self.doctype not in ("Purchase Receipt", "Purchase Invoice", "Purchase Order"):

	ref_doctype_map = {
		"Purchase Order": "Sales Order Item",
		"Purchase Receipt": "Delivery Note Item",
		"Purchase Invoice": "Sales Invoice Item",

	ref_doctype = ref_doctype_map.get(self.doctype)
	items = self.get("items")
	for d in items:
		if not cint(self.get("is_return")):
			# Get outgoing rate based on original item cost based on valuation method

			if not d.get(frappe.scrub(ref_doctype)):
				posting_time = self.get("posting_time")
				if not posting_time and self.doctype == "Purchase Order":
					posting_time = nowtime()

				outgoing_rate = get_incoming_rate(
						"item_code": d.item_code,
						"warehouse": d.get("from_warehouse"),
						"posting_date": self.get("posting_date") or self.get("transation_date"),
						"posting_time": posting_time,
						"qty": -1 * flt(d.get("stock_qty")),
						"serial_no": d.get("serial_no"),
						"batch_no": d.get("batch_no"),
						"voucher_type": self.doctype,
						"allow_zero_valuation": d.get("allow_zero_valuation"),

				rate = flt(outgoing_rate * (d.conversion_factor or 1), d.precision("rate"))
				***field = "incoming_rate" if self.get("is_internal_supplier") else "rate"***
				rate = flt(
					frappe.db.get_value(ref_doctype, d.get(frappe.scrub(ref_doctype)), field)
					* (d.conversion_factor or 1),

			if self.is_internal_transfer():
				if self.doctype == "Purchase Receipt" or self.get("update_stock"):
					if rate != d.rate:
						d.rate = rate
								"Row {0}: Item rate has been updated as per valuation rate since its an internal stock transfer"
					d.discount_percentage = 0.0
					d.discount_amount = 0.0
					d.margin_rate_or_amount = 0.0

Any ideas how to elevate this to the erpnext team to check?

The particular line in this code is on line number 313 of and is as follows:

field = "incoming_rate" if self.get("is_internal_supplier") else "rate"

In Purchase Order Item table I am unable to find any field titled “incoming_rate”.

I have raised the following issue on Erpnext’s issues page on Github:

Cannot Submit Purchase Order that has been Created from Sales Order when Supplier is Internal Supplier #33349

The error occurs due to the absence of the ‘incoming_rate’ field in either the sales order or purchase order. To resolve this issue in Frappe:

1. Add a new custom field named ‘incoming_rate’ to the Sales Order.
2. Add the same custom field (‘incoming_rate’) to the Purchase Order.

Ensure that both custom fields are of the same type and have the necessary permissions. This addition ensures that the required field exists for the condition check during the creation of internal purchase orders in Frappe.


facing same issue on version 15 anyone can help to resolved

Server Error

pymysql.err.OperationalError: (1054, “Unknown column ‘published_in_website’ in ‘field list’”)
Possible source of error: webshop (app)