Upgrade to 2.7 fails - quiz_questions_instances already exists

Upgrade to 2.7 fails - quiz_questions_instances already exists

- Sarah Smith の投稿
返信数: 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?

Sarah Smith への返信

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

- Tim Hunt の投稿
画像 Core developers 画像 Documentation writers 画像 Particularly helpful Moodlers 画像 Peer reviewers 画像 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.

Tim Hunt への返信

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

- 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?

Sarah Smith への返信

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

- Tim Hunt の投稿
画像 Core developers 画像 Documentation writers 画像 Particularly helpful Moodlers 画像 Peer reviewers 画像 Plugin developers

Yes, it should.

Tim Hunt への返信

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

- 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!

Tim Hunt への返信

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

- 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.




Mónica Andrea Arboleda M. への返信

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

- Tim Hunt の投稿
画像 Core developers 画像 Documentation writers 画像 Particularly helpful Moodlers 画像 Peer reviewers 画像 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.

Tim Hunt への返信

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

- 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 笑顔


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

Mark Hamilton への返信

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

- Tim Hunt の投稿
画像 Core developers 画像 Documentation writers 画像 Particularly helpful Moodlers 画像 Peer reviewers 画像 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).

Tim Hunt への返信

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

- 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.

Mark Hamilton への返信

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

- Tim Hunt の投稿
画像 Core developers 画像 Documentation writers 画像 Particularly helpful Moodlers 画像 Peer reviewers 画像 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.)

Mark Hamilton への返信

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

- 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.

Mark Hamilton への返信

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

- Tim Hunt の投稿
画像 Core developers 画像 Documentation writers 画像 Particularly helpful Moodlers 画像 Peer reviewers 画像 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.

Tim Hunt への返信

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

- 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?

Mark Hamilton への返信

Re: Upgrade to 2.7 fails - quiz_questions_instances already exists

- Tim Hunt の投稿
画像 Core developers 画像 Documentation writers 画像 Particularly helpful Moodlers 画像 Peer reviewers 画像 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.