Adding docField to a doctype

I wanted to add a doc_field to a docType via code. But i was unable to find the way.
Please guide me if you got any!

You need to acess the DocType using frappe.get_doc("Doctype", "MyAwesomeDoctype")
Now you can access the child table that holds the fields and add the docfields you wish.

Please note, adding or deleting docfields on the fly is not a good practice. Create all the fields you want and then hide or show them using controllers on client side

okay but in which file should i insert this statement. I am trying to create a new docfield called emergency contact in patient doctype of healthcare module. I have set the developer mode 1 and cleared cache didnt work. Could you please help me with this

You can go to panel, in patient doctype click on menu → Edit Doctype → Then add field.
Save n You are good to go(You need to be in developer mode).

Otherwise you can patient.json & can execute bench migrate

1 Like

It works. Thank you:smiley: