Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-74859

"questionid cannot be added" if question_bank_entries exists before upgrade

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Minor Minor
    • None
    • 4.0.1, 4.0.4
    • Database SQL/XMLDB
    • MOODLE_400_STABLE
    • MDL-74859-question_bank_entries
    • Hide
      1.  Set up a Moodle 3.11 site using MySQL or MariaDB for the database.
      2.  Add a course.
      3. Add a quiz to the course.
      4.  Add a question to the quiz.
      5. Back up the database using mysqldump (for example mysqldump -u root -p --single-transaction --default-character-set=utf8mb4 moodle > moodle.sql).
      6. Upgrade the site to Moodle 4.0.
      7. Restore the database from step 5 using the mysql command (for example mysql -u root -p moodle < moodle.sql).
      8. Upgrade the site again to Moodle 4.0.

      Expected results

      Error Default exception handler: Table "question_bank_entries" already exists but not error Default exception handler: Unknown DDL library error Debug: Field question_bank_entries->questionid cannot be added. Not null fields added to non empty tables require default value. Create skipped.

      Show
       Set up a Moodle 3.11 site using MySQL or MariaDB for the database.  Add a course. Add a quiz to the course.  Add a question to the quiz. Back up the database using mysqldump (for example mysqldump -u root -p --single-transaction --default-character-set=utf8mb4 moodle > moodle.sql ). Upgrade the site to Moodle 4.0. Restore the database from step 5 using the mysql command (for example mysql -u root -p moodle < moodle.sql ). Upgrade the site again to Moodle 4.0. Expected results Error Default exception handler: Table "question_bank_entries" already exists but not error Default exception handler: Unknown DDL library error Debug: Field question_bank_entries->questionid cannot be added. Not null fields added to non empty tables require default value. Create skipped .

      If a site with a non-empty question bank is upgraded to 4.0, then rolled back by restoring a MySQL/MariaDB dump file, and the upgrade attempted again you get the error:

      Default exception handler: Unknown DDL library error Debug: Field question_bank_entries->questionid cannot be added. Not null fields added to non empty tables require default value. Create skipped
      Error code: ddlunknownerror
      * line 540 of /lib/ddl/database_manager.php: ddl_exception thrown
      * line 3935 of /lib/db/upgrade.php: call to database_manager->add_field()
      * line 1875 of /lib/upgradelib.php: call to xmldb_main_upgrade()
      * line 196 of /admin/cli/upgrade.php: call to upgrade_core()

      There are two issues here:

      1. I think the upgrade should fail because mdl_question_bank_entries already exists but that's not what's causing the above error.
      2. The code has a mistake which results in this error (column questionid incorrectly created as NOT NULL because a bogus constant is passed to $notnull) so actually this error shouldn't happen at all.

      Steps to reproduce this

      1. Set up a Moodle 3.11 site using MySQL or MariaDB for the database.
      2. Add a course.
      3. Add a quiz to the course.
      4. Add a question to the quiz.
      5. Back up the database using mysqldump (for example mysqldump -u root -p --single-transaction --default-character-set=utf8mb4 moodle > moodle.sql).
      6. Upgrade the site to Moodle 4.0.
      7. Restore the database from step 5 using the mysql command (for example mysql -u root -p moodle < moodle.sql).
      8. Upgrade the site again to Moodle 4.0.

      Expected results

      I would expect the error Default exception handler: Table "question_bank_entries" already exists.

      Actual results

      Error Default exception handler: Unknown DDL library error Debug: Field question_bank_entries->questionid cannot be added. Not null fields added to non empty tables require default value. Create skipped.

            leonstr Leon Stringer
            leonstr Leon Stringer
            Votes:
            3 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.