Upgrade to 2.7 fails - quiz_questions_instances already exists

Upgrade to 2.7 fails - quiz_questions_instances already exists

by Sarah Smith -
Number of replies: 14

I have been attempting to update my site from 2.6 to 2.7. I had done this last month, but we ran into another issue (realized my template was 2.7 compatible yet), so I reverted back to 2.6.

Well, now my template has been updated, so I wanted to try the 2.7 update again. I did my plugins check and then went on to upgrade the database. However, I get an error:

Moodle 2.7 Upgrade Error

I read suggestions elsewhere about dropping your database tables and doing a fresh install. So, that's what I did. I dropped all of my database tables and did a new install of 2.7. After that, I restored my database to the backup that I had taken. Unfortunately, all that did was take me back to where I started - I had to go through the PHP check and then the plugins check again and then it wanted to update the database.

I have also tried updating to the newest version of 2.6 (build 20140814) and that was successful. Then I attempted to upgrade to 2.7 from there, but I ran into the same error message.

Is there something about the quiz module that is preventing my update? What can I do to finally get my site updated to 2.7?

Average of ratings: -
In reply to Sarah Smith

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

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

First, the error is confusing. What is actually happening is that a table is being renamed from quiz_question_instances to quiz_slots. https://github.com/moodle/moodle/blob/MOODLE_27_STABLE/mod/quiz/db/upgrade.php#L524

(OK, so the wrong error message is a bug, and I have just submitted a fix. MDL-46918)

The error message in your case should say:

Table 'quiz_slots' already exists.

Now, that table did not exist in Moodle 2.6, and should exist in Moodle 2.7. So, your first failed upgrade must of created it, and you must have failed to revert properly, and everything else follows from there.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

by Sarah Smith -

Hmm, ok, that sort of clears it up, but kind of weird that it didn't go away when I rolled back after my first attempt. Would removing the quiz_slots table resolve the issue?

In reply to Sarah Smith

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

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

Yes, it should.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

by Sarah Smith -

Perfect! I deleted mdl_quiz_slots and tried it again. I got another message about mdl_message_airnotifier_devices - I deleted that and tried again. I got another message about mdl_logstore_standard_log - I deleted that and tried again and finally it went through.

Thanks so much - I really appreciate your help!

In reply to Tim Hunt

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

by Mónica Andrea Arboleda M. -

Hello Tim,


Can you help me? Do you know if table question_states has been renamed or changed for Moodle 2.7? 

My question is because that table does not appear in the database.




Average of ratings: Useful (1)
In reply to Mónica Andrea Arboleda M.

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

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

The question_states table is removed in the upgrade to Moodle 2.7.

It has not acutally been used since the upgrade to Moodle 2.1, but for various reasons we did not drop it immediately.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

by Mark Hamilton -

I have a slightly different question, but a google search of "mdl_quiz_slots does not exist" brought me to this thread...


After preforming an upgrade from 2.5 to 2.7 we've only hit one snag. When a user attempts a quiz they are presented with an error (and the following stacktrace if debugging is set to DEVELOPER):


Debug info: ERROR: relation "mdl_quiz_slots" does not exist
LINE 4: JOIN mdl_quiz_slots slot ON slot.quizid = $1 A...
^
SELECT q.*, qc.contextid, slot.maxmark, slot.id AS slotid, slot.slot, slot.page
FROM mdl_question q
JOIN mdl_question_categories qc ON q.category = qc.id
JOIN mdl_quiz_slots slot ON slot.quizid = $1 AND q.id = slot.questionid

ORDER BY slot.slot
[array (
0 => '1',
)]
Error code: dmlreadexception
Stack trace:
  • line 443 of /lib/dml/moodle_database.php: dml_read_exception thrown
  • line 244 of /lib/dml/pgsql_native_moodle_database.php: call to moodle_database->query_end()
  • line 764 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->query_end()
  • line 785 of /lib/questionlib.php: call to pgsql_native_moodle_database->get_records_sql()
  • line 131 of /mod/quiz/attemptlib.php: call to question_preload_questions()
  • line 223 of /mod/quiz/attemptlib.php: call to quiz->preload_questions()
  • line 192 of /mod/quiz/view.php: call to quiz->has_questions()



The strange thing is, we've created a duplicate of this server and it's database, but never encountered this error on our 'test' upgrade. Now that we're on a production server, of course this happens smile


Any help would be greatly appreciated! Apologies if I'm using the wrong thread.

In reply to Mark Hamilton

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

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

Did you actually run the upgrade? Did it complete successfully?

During the upgrade quiz_question_instances gets renamed to quiz_slots (and various other changes are made to the table).

In reply to Tim Hunt

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

by Mark Hamilton -

Thanks for the response!

We ran the upgrade successfully* from the server command line. Moodle appeared to load correctly in a browser, but after a test run through the course, the Quiz links direct to an error page (as I mentioned before). 

*Our quiz_question_instances table was never renamed to quiz_slots. This indicates that the upgrade.php script didn't actually do it's job even though it reported success. Is there a way to get a more verbose output from the script?

Any thoughts or suggestions would be very much appreciated.

In reply to Mark Hamilton

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

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

Do you have a back-up of the database from before the upgrade? If so, start by comparing the tables defined in the backup with what should exist (defined in mod/quiz/db/install.xml - as it was in Moodle 2.6 https://github.com/moodle/moodle/blob/MOODLE_26_STABLE/mod/quiz/db/install.xml).

Then, compare the current database structure you have with the current mod/quiz/db/install.xml (https://github.com/moodle/moodle/blob/MOODLE_27_STABLE/mod/quiz/db/install.xml).

In either case, you probably also look at mod/quiz/db/upgrade.php (https://github.com/moodle/moodle/blob/MOODLE_27_STABLE/mod/quiz/db/upgrade.php#L409) to see what change should have been applied in the move from 2.6 -> 2.7.

Once you have done all that, with luck you will have a pretty good idea what state your DB is in now, compared to how it should be, and then you may be able to work out how to fix it up manually.

(You may find that https://docs.moodle.org/dev/Upgrade_API helps you understand those various files I linked to.)

In reply to Mark Hamilton

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

by Mark Hamilton -

To follow up, we may have a bad case of versionitis as a result of using custom modifications to the quiz module. Can you point me in the right direction on how to change the version of a module so the upgrade.php script reads a new version?

We've determined the change must be made in more places than just the version.php of the module, for the upgrade script to read the old (modified) version number.

In reply to Mark Hamilton

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

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

Yes, it is surprisingly tricky.

You need to:

  • Set the value of plugin = mod_quiz / name = version in the mdl_config_plugins table.
  • Deleted the row with name = allversionshash value from mdl_config table.
  • Purge caches.

In reply to Tim Hunt

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

by Mark Hamilton -

This is what we've been hoping for. Thank you!

However, we're upgrading from 2.5 to 2.7, and we don't have an 'allversionshash' value in mdl_config. Was it called something different in 2.5?


On our old 2.5 db dump, I see our bad quiz version number in mdl_modules, mdl_tool_customlang_components and mdl_upgrade_log tables.

Assuming the upgrade doesn't consider mdl_upgrade_log in its process, is there any reason to update the version number in mdl_modules and mdl_tool_customlang_components?

In reply to Mark Hamilton

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

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

Sorry, I forget exactly when things changed, particularly when it was that long ago.

Right, so in that version of Moodle, the key one to change is the one in mdl_modules. That should be all you need to do.