TLS Certificate Automation: Get Ready Before March 2027
TLS certificates now last 200 days and drop to 100 in March 2027. A practical guide to automating renewals with ACME and monitoring expiry before outages.
Fix the Moodle 'Can not find data record in database table qtype_multichoice_options' error: the 2020 SQL fix, plus a safer 2026 method for Moodle 4.x and 5.x.

If students or teachers see Can not find data record in database table qtype_multichoice_options when they attempt, edit or preview a quiz, the cause is almost always in the question bank. Moodle is looking for the options row of a multichoice question, and that row does not exist. Below is the fix that worked for me in 2020, followed by the safer method I would use today.
In my case the cause was buggy questions brought in by file import. Each multichoice question in mdl_question should have a matching row in mdl_qtype_multichoice_options. With these imported questions, the question existed but its options row did not.
When Moodle loads such a question, the lookup fails. The debug output shows a query like SELECT * FROM {qtype_multichoice_options} WHERE questionid = ? with error code invalidrecord, as reported on the Moodle forums.
The examples below use the default mdl_ table prefix. Change it if your site uses a different one.
SELECT t1.id, t1.name
FROM mdl_question t1
LEFT JOIN mdl_qtype_multichoice_options t2 ON t1.id = t2.questionid
WHERE t1.qtype = 'multichoice' AND t2.id IS NULL;
DELETE FROM mdl_question WHERE id IN (id1, id2, ...);
At the time this was the accepted workaround. Forum advice said the only option was to delete the record directly with a tool such as phpMyAdmin or pgAdmin.
Do not run this DELETE on Moodle 4.0 or later. The next section explains why.
The detection query still works. The delete does not.
question_references record, which links to a question_bank_entries record. The question_versions table then links that entry to each version in mdl_question, as explained in this forum thread. Deleting only from mdl_question leaves broken rows behind.\mod_qbank\task\transfer_question_categories and \mod_qbank\task\transfer_questions have finished before you change anything in the database.Please test this on a staging copy first.
Back up the database and the moodledata folder. Put the site in maintenance mode.
Find the broken questions, with their version link and attempt count:
SELECT q.id, q.name, qv.questionbankentryid,
(SELECT COUNT(1) FROM mdl_question_attempts qa
WHERE qa.questionid = q.id) AS attempts
FROM mdl_question q
LEFT JOIN mdl_qtype_multichoice_options o ON o.questionid = q.id
LEFT JOIN mdl_question_versions qv ON qv.questionid = q.id
WHERE q.qtype = 'multichoice' AND o.id IS NULL;
Save the output. Any row with attempts above zero needs extra care.
mdl_qtype_multichoice_options with questionid set to that question's ID and default values for the other columns.Do not guess the columns. Open question/type/multichoice/db/install.xml in your own Moodle code and take the exact column list, types and defaults from there, because the columns have changed between versions. Write and test the INSERT on staging, confirm the question opens, and only then repeat it on production.
Fix or delete through Moodle. Once the row exists, the question loads again. Open the Question bank, then edit the question or delete it there. Moodle will clean up the versions, bank entries and files itself.
If you must script it, use Moodle's own question delete function in lib/questionlib.php, not raw SQL, so the related tables are handled together.
qtype_multichoice_options.DELETE or INSERT on a production Moodle database without a tested backup.The main lesson from revisiting this note is that the diagnosis has not changed, but the database has. On modern Moodle, repair the broken record so Moodle can clean up after itself, rather than deleting rows by hand.
📝 First written from my own work in 2020; updated and expanded in November 2026 with AI assistance, keeping my original fix. Spotted something wrong? Tell me.