may i know how to generate random or composite unique key values for name field of child table
i asked this when i try to insert values to student batch student table
frappe.db.sql("""insert into
tabStudent Batch Student (
parent,
student,
parentfield,
parenttype,
student_name,
name) values (%s,%s,%s,%s,%s,%s)""",(student_batch,id,"students","Student Batch",st_name))
i was getting an error
Traceback (most recent call last):
File "/home/shahid/think/frappe-think/apps/frappe/frappe/app.py", line 55, in application
response = frappe.handler.handle()
File "/home/shahid/think/frappe-think/apps/frappe/frappe/handler.py", line 19, in handle
execute_cmd(cmd)
File "/home/shahid/think/frappe-think/apps/frappe/frappe/handler.py", line 40, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File "/home/shahid/think/frappe-think/apps/frappe/frappe/__init__.py", line 898, in call
return fn(*args, **newargs)
File "/home/shahid/think/frappe-think/apps/erpnext/erpnext/schools/doctype/student_applicant/student_applicant.py", line 85, in add_selected_student_to_childtable
print frappe.db.sql("""insert into `tabStudent Batch Student` (`parent`,`student`,`parentfield`,`parenttype`,`student_name`,`name`) values (%s,%s,%s,%s,%s,%s)""",(student_batch,id,"students","Student Batch",st_name,'xxx'))
File "/home/shahid/think/frappe-think/apps/frappe/frappe/database.py", line 137, in sql
self._cursor.execute(query, values)
File "/home/shahid/think/frappe-think/env/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "/home/shahid/think/frappe-think/env/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
IntegrityError: (1062, "Duplicate entry 'xxx' for key 'PRIMARY'")
before i was using this code
# doc = frappe.get_doc({
# "doctype": "Student Batch Student",
# "parent": student_batch,
# "parentfield":"students",
# "parenttype":"Student Batch",
# "student_name":name,
# "student": id
# })
# if doc.insert():
# return 'success'
but this code runs only once if it is in for loop
and i was getting an error in terminal
Error on request:
Traceback (most recent call last):
File "/home/shahid/think/frappe-think/env/lib/python2.7/site-packages/werkzeug/serving.py", line 209, in run_wsgi
execute(self.server.app)
File "/home/shahid/think/frappe-think/env/lib/python2.7/site-packages/werkzeug/serving.py", line 200, in execute
write(data)
File "/home/shahid/think/frappe-think/env/lib/python2.7/site-packages/werkzeug/serving.py", line 168, in write
self.send_header(key, value)
File "/usr/lib64/python2.7/BaseHTTPServer.py", line 401, in send_header
self.wfile.write("%s: %s\r\n" % (keyword, value))
IOError: [Errno 32] Broken pipe