Repeated Quiz Error Across All Classes

Tim at Lone Pine Koala Sanctuary
Re: Repeated Quiz Error Across All Classes
Core developersDocumentation writersParticularly helpful MoodlersPlugin 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.

Average of ratings: -