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

迁移Moodle至独立服务器时遇MariaDB 'id'字段无默认值错误求助

Moodle迁移后数据库写入错误:Field 'id' doesn't have a default value

环境信息

  • Moodle版本:v4.1.4
  • PHP版本:8.1
  • 数据库:MariaDB 15.1(Debian系统,搭配Froxlor面板)

问题详情

将Moodle从虚拟主机迁移至独立服务器,已完成以下操作:

  1. 迁移所有文件至新服务器
  2. 导入原数据库到新服务器的MariaDB
  3. 更新config.php配置文件以匹配新环境

完成后访问站点,出现数据库写入错误,具体错误信息如下:

Error writing to database
Debug info: Field 'id' doesn't have a default value
INSERT INTO mdl_sessions (state,sid,sessdata,userid,timemodified,timecreated,lastip,firstip) VALUES(?,?,?,?,?,?,?,?)
[array (
0 => 0,
1 => 'om9er1b27to3rqt5broqcknooi',
2 => NULL,
3 => 0,
4 => 1709207762,
5 => 1709207762,
6 => '95.90.242.199',
7 => '95.90.242.199',
)]
Error code: dmlwriteexception
Stack trace:
line 497 of /lib/dml/moodle_database.php: dml_write_exception thrown
line 293 of /lib/dml/moodle_read_slave_trait.php: call to moodle_database->query_end()
line 1362 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->query_end()
line 1408 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
line 573 of /lib/classes/session/manager.php: call to mysqli_native_moodle_database->insert_record()
line 550 of /lib/classes/session/manager.php: call to core\session\manager::add_session_record()
line 165 of /lib/classes/session/manager.php: call to core\session\manager::initialise_user_session()
line 139 of /lib/classes/session/manager.php: call to core\session\manager::start_session()
line 842 of /lib/setup.php: call to core\session\manager::start()
line 33 of /config.php: call to require_once()
line 30 of /index.php: call to require_once()

已尝试长时间搜索解决方案但未找到有效方法,恳请各位提供帮助!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 00:03:10