How to add child records from a task

Hello Gentlemen,

I customized the DocType Employee by adding a child table “Mitarbeiter FTE”. I’m trying to write a migrate task that runs once and adds one entry to “Mitarbeiter FTE” for all Employees.

In my application I created a file erpituc/tasks/ containing this code:

import frappe

def migrate_mitarbeiter_fte():
    names = frappe.get_list("Employee")
    for name in names:
        employee = frappe.get_doc("Employee", name)
        if not employee.mitarbeiter_ftes:
            # This line causes an error
            mitarbeiter_fte = employee.append("Mitarbeiter FTE", {}) 
            mitarbeiter_fte.gueltig_ab = '2021-11-01'
            mitarbeiter_fte.fte = employee.current_fte_value_per_40_hours_a_week

By executing it with bench execute erpituc.tasks.employee.migrate_mitarbeiter_fte I got this error:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/", line 213, in execute
    ret = frappe.get_attr(method)(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/erpituc/erpituc/tasks/", line 8, in migrate_mitarbeiter_fte
    mitarbeiter_fte = employee.append("Mitarbeiter FTE", {})
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/", line 183, in append
    value = self._init_child(value, key)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/", line 218, in _init_child
    value["doctype"] = self.get_table_field_doctype(key)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/", line 338, in get_table_field_doctype
    return self.meta.get_field(fieldname).options
AttributeError: 'NoneType' object has no attribute 'options'

How do I create a function that can be called with bench execute that adds childs to Employee?

I found an example here (How to add new row in child table using Python - #2 by rohit_w) but I must be doing something wrong.

I found the solution to my problem:

You don’t use the name of the DocType but the name of the field. To get my code working I changed the line above to:

mitarbeiter_fte = employee.append("mitarbeiter_ftes", {})