dmlwriteexception when sending a message

dmlwriteexception when sending a message

by frederic Grebot -
Number of replies: 2

Hi everyone

So... I'm a PHP dev, who also administrate several moodle at work.
I migrated all of ours moodle from 3.5/3.8 to 3.9.8 in August (with PHP 7.4, mariadb 10.5)

Since then, users can't send private message

The error is :

Debug info: Column 'contextid' cannot be null
INSERT INTO mdl_message_conversations (type,name,convhash,component,itemtype,itemid,contextid,enabled,timecreated,timemodified) VALUES(?,?,?,?,?,?,?,?,?,?)
[array (
0 => 1,
1 => NULL,
2 => 'f060c567554ebcac9ace48e81b29bc4707f6809b',
3 => NULL,
4 => NULL,
5 => NULL,
6 => NULL,
7 => 1,
8 => 1632747922,
9 => 1632747922,
)]
Error code: dmlwriteexception
Stack trace:
  • line 489 of /lib/dml/moodle_database.php: dml_write_exception thrown
  • line 1357 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
  • line 1403 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
  • line 2556 of /message/classes/api.php: call to mysqli_native_moodle_database->insert_record()
  • line 138 of /lib/messagelib.php: call to core_message\api::create_conversation()
  • line 367 of /message/lib.php: call to message_send()
  • line 32 of /admin/user/user_bulk_message.php: call to message_post_message()
I tried several things, and so far, if I change the defaut value of the column contextid form the table mdl_message_conversations to NOT NULL and value=1, message can be read but not written (error), and if I change it to NULLand value=1, messages can be written but not read...

I completly stuck, don't really known what to do/try now, have been searching the web for hours...
My last shot is doing the minor update to moodle 3.9.10

Any guess ? Any lead ?

Average of ratings: -
In reply to frederic Grebot

Re: dmlwriteexception when sending a message

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

Column mdl_message_conversations.contextid should allow NULLs. The Column 'contextid' cannot be null message suggests your database has this column set to NOT NULL. I think you should change that.

For reference here's the SHOW CREATE TABLE for that table on my Moodle 3.9 test site:

CREATE TABLE `mdl_message_conversations` ( 
  `id` bigint(10) NOT NULL AUTO_INCREMENT,
  `type` bigint(10) NOT NULL DEFAULT 1,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `convhash` varchar(40) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `component` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `itemtype` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `itemid` bigint(10) DEFAULT NULL,
  `contextid` bigint(10) DEFAULT NULL,
  `enabled` tinyint(1) NOT NULL DEFAULT 0,
  `timecreated` bigint(10) NOT NULL,
  `timemodified` bigint(10) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `mdl_messconv_typ_ix` (`type`),
  KEY `mdl_messconv_con_ix` (`convhash`),
  KEY `mdl_messconv_comiteitecon_ix` (`component`,`itemtype`,`itemid`,`contextid`),
  KEY `mdl_messconv_con2_ix` (`contextid`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=COMPRESSED COMMENT='Stores all message conversations'
In reply to Leon Stringer

Re: dmlwriteexception when sending a message

by frederic Grebot -
Thx for your answer
I know that, I change it trying to solve my problem, I rollback my change. When I run the cli script check_database_schema, it's ok
I have updated these past few days all my moodle for moodle 3.9.10, hoping it will solve my problem, but no...