Hi there,
I have the following issue in Moodle 2.7:
INSERT INTO mdl_question_attempts (questionusageid,slot,behaviour,questionid,variant,maxmark,minfraction,maxfraction,flagged,questionsummary,rightanswer,responsesummary,timemodified) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)
[array (
0 => 2073,
1 => 1,
2 => 'deferredfeedback',
3 => '363',
4 => 1,
5 => '1.0000000',
6 => 0,
7 => 1,
8 => 0,
9 => 'When may fit adult ewes need worming?: Lambing; Weaning; Tupping; All of the above',
10 => 'Lambing',
11 => NULL,
12 => 1487081616,
)]
Error code: dmlwriteexception
- line 448 of /lib/dml/moodle_database.php: dml_write_exception thrown
- line 1178 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
- line 1224 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
- line 120 of /question/engine/datalib.php: call to mysqli_native_moodle_database->insert_record()
- line 90 of /question/engine/datalib.php: call to question_engine_data_mapper->insert_question_attempt()
- line 100 of /question/engine/lib.php: call to question_engine_data_mapper->insert_questions_usage_by_activity()
- line 289 of /mod/quiz/locallib.php: call to question_engine::save_questions_usage_by_activity()
- line 185 of /mod/quiz/startattempt.php: call to quiz_attempt_save_started()
This appears to be happening because the counter used to store the values for "mdl_quiz_attempts.uniqueid" and, related, entries in "mdl_question_attemts.questionusageid" is out of sync. For instance, it's trying to create an entry here with value of 2073, but the highest in the database at the moment is 2076.
The indexes appear to be correctly configured in the database (MySQL, InnoDB).
I have some questions for anyone who understands the quiz process better than me -
- Does the question attempt get created before the associated quiz attempt? If so, why? The unique constraint on mdl_quiz_attempts.uniqueid should have caught this already but it hasn't. I can only assume we're creating "child" records before "parent" which is ... strange.
- Where is this unique ID managed from?
- Has anyone else seen this kind of issue? I note some examples from some years ago of a similar error message caused by "orphaned data" on the migration from 1.9 -> 2.x but this is a server which has always been in the 2.7.x version family.
- Might this be something missing in my migration process - this appears to have happened on our staging and development servers, and not (at least not that I have been able to reproduce) on our production server. I wonder if the tracking of the quiz attempts unique ID is carried over from previous attempts done on that server, and when we copy over the new prod database (with obviously more records in it) we get this mismatch, maybe?