-
Bug
-
Resolution: Won't Fix
-
Minor
-
None
-
4.0.1, 4.0.4
-
MOODLE_400_STABLE
-
MDL-74859-question_bank_entries -
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:
- I think the upgrade should fail because mdl_question_bank_entries already exists but that's not what's causing the above error.
- 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
- 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
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.