Problem Upgrading Moodle database from version 3.11.6 to 4.0

Problem Upgrading Moodle database from version 3.11.6 to 4.0

by G E -
Number of replies: 11

I have the following problem trying to update moodle
The server is Ubuntu 20.4 php 7.4.3 mysql 8.0.28 apache 2.4.41-4

Upgrading to new versionSystem

Unknown DDL library error

More information about this error

Debug info: Field question_bank_entries->questionid cannot be added. Not null fields added to non empty tables require default value. Create skipped
Error code: ddlunknownerror
Stack trace:
  • 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 525 of /admin/index.php: call to upgrade_core()

Average of ratings: -
In reply to G E

Re: Problem Upgrading Moodle database from version 3.11.6 to 4.0

by David Husband -

I am having the same problem. I've tried upgrading with 3.11.6 and 3.11.7

mariadb 10.3.34 php 7.4.29

In reply to David Husband

Re: Problem Upgrading Moodle database from version 3.11.6 to 4.0

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Could it be this: "Unable to upgrade from Moodle 3.9.13+ to 4.0.1" https://moodle.org/mod/forum/discuss.php?d=434676#p1749107 ?
In reply to Visvanath Ratnaweera

Re: Problem Upgrading Moodle database from version 3.11.6 to 4.0

by David Husband -
I tried changing the lines of code as suggested and got the following error.

Duplicate entry '194-mod_quiz-slot-16' for key 'lms_quesrefe_usicomqueite_uix'
INSERT INTO lms_question_references
(usingcontextid, component, questionarea, itemid, questionbankentryid)
SELECT c.id, 'mod_quiz', 'slot', qs.id, qv.questionbankentryid
FROM lms_question q
JOIN lms_question_versions qv ON q.id = qv.questionid
JOIN lms_quiz_slots qs ON q.id = qs.questionid
JOIN lms_modules m ON m.name = 'quiz'
JOIN lms_course_modules cm ON cm.module = m.id AND cm.instance = qs.quizid
JOIN lms_context c ON c.instanceid = cm.id AND c.contextlevel = 70
WHERE q.qtype <> 'random'
[array (
)]
Error code: dmlwriteexception

I tried removing the table as suggested and this produce a new error that the table was missing.

I have tried the latest build available but get the same errors.
In reply to G E

Odp: Problem Upgrading Moodle database from version 3.11.6 to 4.0

by Piotr Janiszewski -

We have exactly the same problem with upgrade from 3.11.7 to 4.0 and 4.0.1.

In reply to G E

Re: Problem Upgrading Moodle database from version 3.11.6 to 4.0

by Aditya Shah -

I am also having exactly the same problem. 

Attachment Moodle Upgrade Error.png
In reply to G E

Re: Problem Upgrading Moodle database from version 3.11.6 to 4.0

by Marko Angelski -
The same problem happens with my installation. I'm upgrading from latest 3.11.8+ to latest stable 4.02.
In reply to Marko Angelski

Re: Problem Upgrading Moodle database from version 3.11.6 to 4.0

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

Marko, Aditya, Piotr: The link Visvanath provides takes you to a thread which describes the likely cause and solution: that an upgrade to 4.0 was attempted, then the 3.x MySQL/MariaDB database was restored over the upgraded database which leaves the new 4.0 tables still present. When restoring MySQL/MariaDB databases you must delete and recreate the database before restore, or manually drop (delete) any of the new 4.0 tables yourself. Create a back of the database before making such changes just in case.

Average of ratings: Useful (4)
In reply to Leon Stringer

Re: Problem Upgrading Moodle database from version 3.11.6 to 4.0

by Marko Angelski -
You're right. After the first error, I've restored the database without dropping it first.
Dropping the database and restoring it to an empty database made the upgrade went without any errors.

Thank you!
Average of ratings: Useful (1)
In reply to Leon Stringer

Re: Problem Upgrading Moodle database from version 3.11.6 to 4.0

by Aditya Shah -
That is true. Let me describe what we did.

We finally managed to get Moodle Upgraded to 4.0. The performance took a tank. The site was completely slow. We installed all sorts of optimization like Redis Cache etc., but Nothing helped. Even courses wouldn't load or backup.

So what we did was clean Moodle 4.0.4 install. Installed the theme, plugin etc., and Migrated users as CSV from old installed. Use CLI to back up courses. Used Restore CLI and Web to restore courses in the DB.

This finally got Moodle working.

There was another thing I learnt during backup while installing we also have to make sure our config.php is for MySQL or MariaDB. There are small changes you need to have in Moodle for the same.

If the DB is not the correct DB - it will throw up an error. Moodle uses drivers for it's MariaDB connections. 

Wrong $CFG->dbtype: you need to change it in your config.php file, from 'mysql' to 'mariadb'.
Average of ratings: Useful (1)
In reply to Aditya Shah

Re: Problem Upgrading Moodle database from version 3.11.6 to 4.0

by Andy Hill -
Hi Guys

I am having the same issue, Are there any steps that I can take to ensure a successful upgrade to moodle 4? my knowledge is very limited so please explain in the simplest of terms if possible.

Thanks guys