Can not find data record in qtype_multichoice_options Moodle

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.

Can not find data record in qtype_multichoice_options Moodle

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.

What causes the qtype_multichoice_options error

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.

The original fix (2020)

  1. Run this query and save the result in a text file:
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;
  1. Then delete the broken questions by ID:
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.

Update 2026: why the delete step is no longer safe

The detection query still works. The delete does not.

  • Question versioning (Moodle 4.0). A quiz slot no longer points straight at a question. It points to a 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.
  • Past attempts. Question engine data still points to the exact question version a student attempted. Deleting it can stop past attempts being reviewed and can affect grades.
  • Shared question banks (Moodle 5.0). Shared questions now live inside a Question bank activity, not in the course, category or system context (Moodle 5.0 docs). After upgrading, check that the adhoc tasks \mod_qbank\task\transfer_question_categories and \mod_qbank\task\transfer_questions have finished before you change anything in the database.

Update 2026: the safer fix for Moodle 4.x and 5.x

Please test this on a staging copy first.

  1. Back up the database and the moodledata folder. Put the site in maintenance mode.

  2. 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.

  1. Add the missing options row instead of deleting. For each broken question, insert one row into 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.

  1. 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.

  2. 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.

How to check it worked

  • Run the detection query again. It should return no rows.
  • Preview a few of the affected questions and the quizzes that used them.
  • Review a past attempt that included a repaired question to confirm it still opens.
  • Check the database integrity report if your version provides one, and look for foreign key messages on qtype_multichoice_options.
  • Turn off maintenance mode and purge caches.

Cautions

  • Never run a DELETE or INSERT on a production Moodle database without a tested backup.
  • Do not delete questions that have attempts unless you accept that past reviews and grades may be affected.
  • On a fresh 5.0 upgrade, wait for the question bank transfer tasks to complete first.
  • Once the bank is repaired, re-import the questions from a clean file and spot-check them after import.

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.

Sources & further reading

  1. Moodle 5.0 docs: Sharing question banksdocs.moodle.org
  2. Moodle forums: How the Moodle 4.0 question bank tables workmoodle.org
  3. Moodle forums: Quiz slots, references, bank entries and versionsmoodle.org
  4. Moodle forums: Moodle 5.0 Question bank activity and transfer tasksmoodle.org
  5. Moodle forums: qtype_multichoice_options invalidrecord errormoodle.org
  6. Moodle forums: Original workaround for missing multichoice optionsmoodle.org

📝 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.

Akam Omer
Written by

Akam Omer

IT leader, engineer and security specialist from Erbil with 20+ years across higher education, telecoms, healthcare and government. Founder of BulkSMSIraq, VerifyWay and Kurd.ai.