It was perfectly fine before when teacher adding new quiz in the course but yesterday out of the blue, it said "Database Writing Error" when want to add a new quiz. We tried by duplicate an old quiz and it also said the same but the duplicate was created. We can add or edit questions in this duplicate quiz. Unfortunately, we duplicate more than we want, when we want to delete them, it aslo said the same error and the quizs still there! We do not know what to do, can anyone help?
Version: Moodle 3.1.1+ (Build: 20160817)
Deleting test3 course
Deleted - Completion tracking
Error writing to database
More information about this error
Debug info: Duplicate entry '324-342' for key 'mdl_gradgrad_useite_uix'
INSERT INTO mdl_grade_grades_history (itemid,userid,rawgrade,rawgrademax,rawgrademin,rawscaleid,usermodified,finalgrade,hidden,locked,locktime,exported,overridden,excluded,timemodified,feedback,feedbackformat,information,informationformat,action,oldid,source,loggeduser) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
[array (
0 => '342',
1 => '324',
2 => NULL,
3 => '10.00000',
4 => '0.00000',
5 => NULL,
6 => NULL,
7 => NULL,
8 => '0',
9 => '0',
10 => '0',
11 => '0',
12 => '0',
13 => '0',
14 => 1489129588,
15 => NULL,
16 => '0',
17 => NULL,
18 => '0',
19 => 3,
20 => '337',
21 => 'coursedelete',
22 => '2',
)]
Error code: dmlwriteexception
Stack trace:
line 477 of /lib/dml/moodle_database.php: dml_write_exception thrown
line 1172 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
line 1218 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
line 295 of /lib/grade/grade_object.php: call to mysqli_native_moodle_database->insert_record()
line 1031 of /lib/grade/grade_grade.php: call to grade_object->delete()
line 420 of /lib/grade/grade_item.php: call to grade_grade->delete()
line 403 of /lib/grade/grade_item.php: call to grade_item->delete_all_grades()
line 310 of /lib/grade/grade_category.php: call to grade_item->delete()
line 1408 of /lib/gradelib.php: call to grade_category->delete()
line 4787 of /lib/moodlelib.php: call to remove_course_grades()
line 4704 of /lib/moodlelib.php: call to remove_course_contents()
line 67 of /course/delete.php: call to delete_course()
test3
Error writing to database
More information about this error
Debug info: Duplicate entry '2-342' for key 'mdl_gradgrad_useite_uix'
INSERT INTO mdl_grade_grades_history (itemid,userid,rawgrade,rawgrademax,rawgrademin,rawscaleid,usermodified,finalgrade,hidden,locked,locktime,exported,overridden,excluded,timemodified,feedback,feedbackformat,information,informationformat,action,oldid,source,loggeduser) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
[array (
0 => '342',
1 => '2',
2 => NULL,
3 => '10.00000',
4 => '0.00000',
5 => NULL,
6 => NULL,
7 => NULL,
8 => '0',
9 => '0',
10 => '0',
11 => '0',
12 => '0',
13 => '0',
14 => 1489129497,
15 => NULL,
16 => '0',
17 => NULL,
18 => '0',
19 => 1,
20 => '367',
21 => 'system',
22 => '2',
)]
Error code: dmlwriteexception
Stack trace:
line 477 of /lib/dml/moodle_database.php: dml_write_exception thrown
line 1172 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
line 1218 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
line 357 of /lib/grade/grade_object.php: call to mysqli_native_moodle_database->insert_record()
line 1006 of /lib/grade/grade_grade.php: call to grade_object->insert()
line 647 of /lib/grade/grade_category.php: call to grade_grade->insert()
line 541 of /lib/grade/grade_category.php: call to grade_category->aggregate_grades()
line 727 of /lib/grade/grade_item.php: call to grade_category->generate_grades()
line 1243 of /lib/gradelib.php: call to grade_item->regrade_final_grades()
line 430 of /lib/gradelib.php: call to grade_regrade_final_grades()
line 778 of /mod/quiz/lib.php: call to grade_get_grades()
line 1151 of /mod/quiz/lib.php: call to quiz_grade_item_update()
line 96 of /mod/quiz/lib.php: call to quiz_after_add_or_update()
line 121 of /course/modlib.php: call to quiz_add_instance()
line 275 of /course/modedit.php: call to add_moduleinfo()
Error writing to database
URL:
Debug info:
Duplicate entry '275-342' for key 'mdl_gradgrad_useite_uix' INSERT INTO mdl_grade_grades_history (itemid,userid,rawgrade,rawgrademax,rawgrademin,rawscaleid,usermodified,finalgrade,hidden,locked,locktime,exported,overridden,excluded,timemodified,feedback,feedbackformat,information,informationformat,action,oldid,source,loggeduser) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) [array ( 0 => '342', 1 => '275', 2 => NULL, 3 => '10.00000', 4 => '0.00000', 5 => NULL, 6 => NULL, 7 => NULL, 8 => '0', 9 => '0', 10 => '0', 11 => '0', 12 => '0', 13 => '0', 14 => 1489129393, 15 => NULL, 16 => '0', 17 => NULL, 18 => '0', 19 => 3, 20 => '334', 21 => 'mod/quiz', 22 => '2', )] Error code: dmlwriteexception
Stack trace:
* line 477 of /lib/dml/moodle_database.php: dml_write_exception thrown
* line 1172 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
* line 1218 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
* line 295 of /lib/grade/grade_object.php: call to mysqli_native_moodle_database->insert_record()
* line 1031 of /lib/grade/grade_grade.php: call to grade_object->delete()
* line 420 of /lib/grade/grade_item.php: call to grade_grade->delete()
* line 403 of /lib/grade/grade_item.php: call to grade_item->delete_all_grades()
* line 92 of /lib/gradelib.php: call to grade_item->delete()
* line 818 of /mod/quiz/lib.php: call to grade_update()
* line 198 of /mod/quiz/lib.php: call to quiz_grade_item_delete()
* line 1745 of /course/lib.php: call to quiz_delete_instance()
* line 171 of /course/rest.php: call to course_delete_module()
Re: Add new quiz or delete quiz with database writing error
Tim is right, I am moving this to the gradebook forum.
Re: Add new quiz or delete quiz with database writing error
hi guys, thank you for the advice~ i backup d database and delete all the duplicate entries in mdl_grade_grades_history. Later i can delete all the quiz and courses that have the quiz
But i wonder y it happened in the first place hopefully it wouldnt happened again
Those errors are all coming from the gradebook. (I can tell that by the table/index name in the query.)
I don't know why that would be happening. You could try the gradebook forum?
Re: Add new quiz or delete quiz with database writing error
I would start by backing up and restoring the course to see if that at least gets you a working course. Then, I suspect you either need to get into the database and see if you can find the duplicate item referenced and remove it.
Or preferably, you have been taking course backups or site backups and you could just restore to before the quiz duplication.
Re: Add new quiz or delete quiz with database writing error
thanks for your reply. I will try this first