Repeated Quiz Error Across All Classes

Repeated Quiz Error Across All Classes

by Mike Cahill -
Number of replies: 1

Hello, I am a moodle administrator for our school.  I am not an IT person but a professor.  

We are getting an error message all of the sudden for students who want to get in and take quizzes. 

The following is the entire message we receive when attempting to take a quiz.  

Debug info: Duplicate entry '3026' for key 's2t4v5nj5bquizatte_uni_uix'
INSERT INTO s2t4v5nj5bquiz_attempts (quiz,userid,preview,layout,attempt,timestart,timefinish,timemodified,state,timecheckstate,uniqueid) VALUES(?,?,?,?,?,?,?,?,?,?,?)
[array (
0 => '254',
1 => '336',
2 => 1,
3 => '1,0',
4 => 1,
5 => 1463150424,
6 => 0,
7 => 1463150424,
8 => 'inprogress',
9 => NULL,
10 => 3026,
)]
Error code: dmlwriteexception
Stack trace:
  • line 444 of /lib/dml/moodle_database.php: dml_write_exception thrown
  • line 1080 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
  • line 1122 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
  • line 274 of /mod/quiz/locallib.php: call to mysqli_native_moodle_database->insert_record()
  • line 183 of /mod/quiz/startattempt.php: call to quiz_attempt_save_started()
Can someone walk me through the steps to keep this from happening and get our quiz function up and running again?  I appreciate any help. 

Thanks so much! 

MC

Average of ratings: -
In reply to Mike Cahill

Re: Repeated Quiz Error Across All Classes

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

In the Moodle database, in each table, there is an id column to give each row a unique id. These ids should never repeat.

In the quiz_attempts table, the uniqueid column holds a reference to the id of a row in the question_usages table. Again, these should all be different.

For some reason, on your system, the ids are repeating. This should be impossible.

I can only think of two ways this might happen:

  1. Users have made more than 4,294,967,296 quiz attempts (232) so that the integer ids have wrapped around. This is extremely unlikely.
  2. Someone had edited things directly in the database, and they have screwed up. (E.g. done TRUNCATE question_usages.) This is also pretty unlikely, but more plausible.

Probably the easiest fix is to reset the sequence on the question_usages table, to avoid repeat ids. Do something like

SELECT MAX(uniqueid) FROM mdl_quiz_attempts

to get the largest id in use. Let us suppose that gives 12345. 

Also, to be sure, do

SELECT MAX(id) FROM mdl_question_usages

Let us suppose that gives 23456. 

Then do something like 

ALTER TABLE mdl_question_usages SET AUTO_INCREMENT = 23457

(Set the sequence value to something large than the highest id that has previously been used anywhere.)

However, since you most likely got into this problem by someone directly manipulating the database, you are strongly recommended to take a full Site backup (and know how to restore it) before doing further direct editing in the database.