Moodle
  1. Moodle
  2. MDL-29436

Upgrade fails from 1.9 -> 2.0 -> 2.1 - "Debug info: Unknown column 'questionid' in 'mdl_question_attempts'"

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Cannot Reproduce
    • Affects Version/s: 2.1.1
    • Fix Version/s: None
    • Component/s: Installation, Quiz
    • Labels:
      None
    • Affected Branches:
      MOODLE_21_STABLE
    • Rank:
      18943

      Description

      On fresh installs of Moodle 1.9 the question attempts table is created with two columns, id and modulename, specified in mod/quiz/install.xml. Later on, the Moodle upgrade checks to see if the question_attempts table exists, if it does not, it adds it with other fields. Now coming from a 1.9 upgrade this is going to be ignored as the table exists. This will then cause an error later in the upgrade, the following error occurs. I have created a patch to fix this issue.

      Debug info: Unknown column 'questionid' in 'mdl_question_attempts'
      ALTER TABLE mdl_question_attempts ADD variant BIGINT(10) unsigned NOT NULL DEFAULT 1 AFTER questionid
      Stack trace:
      line 400 of /lib/dml/moodle_database.php: ddl_change_structure_exception thrown
      line 655 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
      line 88 of /lib/ddl/database_manager.php: call to mysqli_native_moodle_database->change_database_structure()
      line 75 of /lib/ddl/database_manager.php: call to database_manager->execute_sql()
      line 586 of /lib/ddl/database_manager.php: call to database_manager->execute_sql_arr()
      line 6492 of /lib/db/upgrade.php: call to database_manager->add_field()
      line 1423 of /lib/upgradelib.php: call to xmldb_main_upgrade()
      line 277 of /admin/index.php: call to upgrade_core()

        Activity

        Show
        Mark Nelson added a comment - I have put my fix here - https://github.com/markn86/moodle/commit/0e694143bf9b6ff83afcff10b9c3d045dd625d43
        Hide
        Mark Nelson added a comment - - edited

        The fix will not retain the information in the old table, which I am aware of. The data is useless from what I can tell, it contains an id and modulename column and the modulename column always contains the value 'quiz' afaik. You could always change the code to rename the table for future sake if you are really worried.

        Show
        Mark Nelson added a comment - - edited The fix will not retain the information in the old table, which I am aware of. The data is useless from what I can tell, it contains an id and modulename column and the modulename column always contains the value 'quiz' afaik. You could always change the code to rename the table for future sake if you are really worried.
        Hide
        Tim Hunt added a comment -

        1. Lots of people have successfully upgraded from 1.9 or to 2.1 without problems, so the code is not fundamentally broken.

        2. The upgrade code keeps the old question_attempts table (renaming it to question_usages) rather than dropping and re-creating for a reason: other tables have foreign-key references to those ids. The question_attempts table in 2.1 is nothing to do with the question_attempts table in Moodle <= 2.0.x. (The renaming was done because the old names were confusing, and it was better to have one confusing update to fix them, than an eternity of confusion in future.)

        3. So, you patch is highly dangerous and wrong. Please read all the upgrade code and try again.

        Show
        Tim Hunt added a comment - 1. Lots of people have successfully upgraded from 1.9 or to 2.1 without problems, so the code is not fundamentally broken. 2. The upgrade code keeps the old question_attempts table (renaming it to question_usages) rather than dropping and re-creating for a reason: other tables have foreign-key references to those ids. The question_attempts table in 2.1 is nothing to do with the question_attempts table in Moodle <= 2.0.x. (The renaming was done because the old names were confusing, and it was better to have one confusing update to fix them, than an eternity of confusion in future.) 3. So, you patch is highly dangerous and wrong. Please read all the upgrade code and try again.
        Hide
        Mark Nelson added a comment -

        Hi Tim,

        I just performed an install on my own server from 1.9 -> 2.1 and 1.9 -> 2.0 -> 2.1 and had no issues. I suspect there was something astray in the Moodle install that created this issue.

        Thanks for looking into it.

        Regards,

        Mark

        Show
        Mark Nelson added a comment - Hi Tim, I just performed an install on my own server from 1.9 -> 2.1 and 1.9 -> 2.0 -> 2.1 and had no issues. I suspect there was something astray in the Moodle install that created this issue. Thanks for looking into it. Regards, Mark
        Hide
        Tim Hunt added a comment -

        Re-opening, so I can resolve it with the correct status.

        Show
        Tim Hunt added a comment - Re-opening, so I can resolve it with the correct status.
        Hide
        Scott Dyreson added a comment -

        Mark,
        I am having the same issue upgrading to 2.2.1. can you post your fix again. your like is unavailable.

        thanks

        scott

        Show
        Scott Dyreson added a comment - Mark, I am having the same issue upgrading to 2.2.1. can you post your fix again. your like is unavailable. thanks scott

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: