Question bank issues when upgrading from 4.5 to 5.x

Question bank issues when upgrading from 4.5 to 5.x

Root cause: legacy SQL and/or code is joining mdl_question directly to mdl_question_categories using q.category, a column removed in the Moodle 4.x refactor and still absent in 5.0+, so category resolution now requires the versioned path through mdl_question_versions and mdl_question_bank_entries.

What changed
Moodle’s question bank was reworked in 4.x, introducing versioned questions and bank entries, which moved the category link off mdl_question into mdl_question_bank_entries.questioncategoryid via mdl_question_versions.questionbankentryid.
Moodle 5.0 continues this model and adds multi‑bank UX changes, so any SQL that expects q.category will fail or misdiagnose issues until rewritten to follow q → qv → qbe → qc.

How it surfaces
Queries or plugins using SELECT ... JOIN mdl_question_categories qc ON q.category = qc.id will error with “Unknown column 'q.category'” or produce incorrect diagnostics for “missing category” on 4.x/5.x sites.
Correct joins must follow mdl_question → mdl_question_versions → mdl_question_bank_entries → mdl_question_categories to reliably detect missing categories or list questions by category.

Evidence and confirmation
Community examples for modern reports explicitly show joining q → qv → qbe → qc, confirming this is the supported path for categories in current releases.
moodle’s developer docs for the Questions subsystem document the 4.x+ architecture shift, which underpins the need for version and bank‑entry joins.

 Fix at sourceUpdate any custom SQL, reports, or plugin code to replace q.category joins with the modern linkage through question_versions and question_bank_entries to question_categories.

If diagnosis of “orphaned” questions is needed, use the modern LEFT JOIN chain and check qc.id IS NULL; do not rely on the pre‑4.0 pattern.

 

Why it “keeps rising”
The issue recurs whenever guidance or scripts written for pre‑4.0 are reused on 4.x/5.x sites, or when upgrades bring older reports/plugins forward without schema‑aware updates.
Because Moodle 5.0 introduced additional question bank UX changes (e.g., multiple banks and “Switch bank”), problems can appear as category or visibility issues even when data is intact, further masking the real cause in legacy SQL.