Child table name in database


I need to insert values of the child table directly in the database, but the problem that I do not know what I have to set the name value to be same as the one that is generated when I am adding the record from the application. Appreciate if someone can help and advise please.

Below is image for the database table of the child table that shows the name field and its values, so how I can set a value that is same shape of those values that are generated from the application?


Why don’t you try data import tool

I need to insert the record using script and not manual insert so data import tool can do nothing here.
I need to insert the record using frappe.db.sql in python.


Share your code that you have tried then maybe someone can help you.

I am just asking what the value of name field should be set when I am inserting the record in the database table, so still I need to know what I have to set before writing the code :slight_smile:


The name field is auto generated by the system as a primary key. I think inserting directly into the DB is not the best method, as you will be bypassing a lot of good things the framework offers, like logging trails.

Why not use Frappe API, for example with Frappe Client as you are using Python anyway? GitHub - frappe/frappe-client: Python library to use Frappe API

@bghayad Can you share use case?

You should use frappe.new_doc() or frappe.get_doc() method.

How to use frappe.new_doc() to fill the child table (specially that the document is already existed, but need to fill its child table)?

Still I did not write the code.

i think using sql cursor to change child table value without changing name attribute

Please check how task are sync in project document.

if document is already created, you need to use frappe.get_doc

But the name is important to be entered because it is the name of the child table in the parent table, how you will keep it blank?

frappe.get_doc can be used to read the values and not to set the values.
Again, I need to insert values in the child table of the existed parent document.

are you want to insert new value or change available value??

I want to insert new values in child table for existed parent document.

Using Third Party application or sql??

Using the python or js code of erpnext …
What the code to be used please?

def change_child(parent_id):
		d = frappe.get_doc({
					"docstatus": 0,
					"doctype": "Expense Claim Detail",
					"name": "New Expense Claim Detail 1",
					"__islocal": 1,
					"__unsaved": 1,
					"owner": frappe.session.user,
					"parent": parent_id,
					"parentfield": "expenses",
					"parenttype": "Expense Claim",
					"expense_date": "2017-10-10",
					"expense_type": "In and Out",
					"default_account": "Field Expense - BSPL",
					"claim_amount": 1000,
					"sanctioned_amount": 1000
		return d.insert(ignore_permissions=True)

child table:Expense Claim Detail
parent table:Expense Claim

I need to insert new values in the child table which is empty (and of course the parent document is existed).
What you mentioned for sure it does not work.

Below is the image that declares that button that I need to click on it (which is Get Employees Who Leaved), so the action will be is to fill the child table that is below the button in the employees who leaved.

I need the method to insert the employees that leaved in the child table (that is determined in the green color) as shown in the below image.

Appreciate the kindly help.


Sorry, maybe I miss understand you.
Regarding to:

“name”: “New Expense Claim Detail 1”,

Do you mean that the d.insert(ignore_permissions=True) will insert the child table in the application and once the user clicked on save, then it will be saved to to the database and will generate a proper name to be placed in the name field in the database?