You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Moodle 4.0升级后题库读取数据库报错求助

Moodle 4.0升级后题库数据库读取异常解决方案

问题情况

接手原部门主管管理的Moodle站点(无计算机操作经验),升级至Moodle 4.0后,题库出现数据库读取异常,无法访问积累的题库内容。调试模式下错误信息如下:

Debug info: Unknown column 'q.category' in 'on clause'
SELECT q.*, qc.contextid FROM mdl6d_question q JOIN mdl6d_question_categories qc ON q.category = qc.id WHERE q.parent = ?
-- line 233 of /question/type/combined/combiner/base.php: call to mysqli_native_moodle_database->get_records_sql()
-- line 190 of /question/type/combined/questiontype.php: call to qtype_combined_combiner_base::get_subq_data_from_db()
-- line 961 of /lib/questionlib.php: call to qtype_combined->get_question_options()
-- line 1028 of /lib/questionlib.php: call to _tidy_question()
-- line 930 of /lib/questionlib.php: call to get_question_options()
-- line 847 of /mod/quiz/report/statistics/report.php: call to question_load_questions()
-- line 83 of /question/bank/statistics/classes/helper.php: call to quiz_statistics_report->load_and_initialise_questions_for_calculations()
-- line 105 of /question/bank/statistics/classes/helper.php: call to qbank_statistics\helper::load_question_stats()
-- line 134 of /question/bank/statistics/classes/helper.php: call to qbank_statistics\helper::load_question_stats_item()
-- line 180 of /question/bank/statistics/classes/helper.php: call to qbank_statistics\helper::calculate_average_question_stats_item()
-- line 63 of /question/bank/statistics/classes/columns/discrimination_index.php: call to qbank_statistics\helper::calculate_average_question_discrimination_index()
-- line 220 of /question/classes/local/bank/column_base.php: call to qbank_statistics\columns\discrimination_index->display_content()
-- line 1199 of /question/classes/local/bank/view.php: call to core_question\local\bank\column_base->display()
-- line 1119 of /question/classes/local/bank/view.php: call to core_question\local\bank\view->print_table_row()
-- line 1095 of /question/classes/local/bank/view.php: call to core_question\local\bank\view->print_table()
-- line 986 of /question/classes/local/bank/view.php: call to core_question\local\bank\view->display_questions()
-- line 756 of /question/classes/local/bank/view.php: call to core_question\local\bank\view->display_question_list()
-- line 60 of /question/edit.php: call to core_question\local\bank\view->display()
[array (
0 => '851',
)]
Error code: dmlreadexception×Dismiss this notification

Stack trace:
line 486 of /lib/dml/moodle_database.php: dml_read_exception thrown
line 291 of /lib/dml/moodle_read_slave_trait.php: call to moodle_database->query_end()
line 1273 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->query_end()
line 233 of /question/type/combined/combiner/base.php: call to mysqli_native_moodle_database->get_records_sql()
line 190 of /question/type/combined/questiontype.php: call to qtype_combined_combiner_base::get_subq_data_from_db()
line 961 of /lib/questionlib.php: call to qtype_combined->get_question_options()
line 1028 of /lib/questionlib.php: call to _tidy_question()
line 930 of /lib/questionlib.php: call to get_question_options()
line 847 of /mod/quiz/report/statistics/report.php: call to question_load_questions()
line 83 of /question/bank/statistics/classes/helper.php: call to quiz_statistics_report->load_and_initialise_questions_for_calculations()
line 105 of /question/bank/statistics/classes/helper.php: call to qbank_statistics\helper::load_question_stats()
line 134 of /question/bank/statistics/classes/helper.php: call to qbank_statistics\helper::load_question_stats_item()
line 180 of /question/bank/statistics/classes/helper.php: call to qbank_statistics\helper::calculate_average_question_stats_item()
line 63 of /question/bank/statistics/classes/columns/discrimination_index.php: call to qbank_statistics\helper::calculate_average_question_discrimination_index()
line 220 of /question/classes/local/bank/column_base.php: call to qbank_statistics\columns\discrimination_index->display_content()
line 1199 of /question/classes/local/bank/view.php: call to core_question\local\bank\column_base->display()
line 1119 of /question/classes/local/bank/view.php: call to core_question\local\bank\view->print_table_row()
line 1095 of /question/classes/local/bank/view.php: call to core_question\local\bank\view->print_table()
line 986 of /question/classes/local/bank/view.php: call to core_question\local\bank\view->display_questions()
line 756 of /question/classes/local/bank/view.php: call to core_question\local\bank\view->display_question_list()
line 60 of /question/edit.php: call to core_question\local\bank\view->display()

解决方案

1. 更新兼容Moodle 4.0的combined题型插件

站点使用的combined题型插件未适配Moodle 4.0的数据库结构变化:

  • 定位站点目录下的/question/type/combined/文件夹,备份原文件夹后,替换为兼容Moodle 4.0的版本。

2. 临时代码修复(无更新插件时)

  • 打开/question/type/combined/combiner/base.php文件,找到第233行的SQL语句:
    SELECT q.*, qc.contextid FROM mdl6d_question q JOIN mdl6d_question_categories qc ON q.category = qc.id WHERE q.parent = ?
    
  • 将其中的q.category修改为q.categoryid,修改后语句为:
    SELECT q.*, qc.contextid FROM mdl6d_question q JOIN mdl6d_question_categories qc ON q.categoryid = qc.id WHERE q.parent = ?
    
  • 保存文件后刷新页面,验证题库是否可正常访问。

3. 操作前必做

执行任何修改前,务必完整备份Moodle的数据库和所有文件,防止数据丢失。

内容的提问来源于stack exchange,提问作者Jacob Daniels

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 21:48:19