Calculated Question Database error

Calculated Question Database error

by Stuart Jones -
Number of replies: 3

Hello,

I am on the latest version of Moodle, and when I try to save a calculated question on page 1 of the form, I get a database error message. This is what shows up with debug on.


Debug info: COLLATION 'utf8mb4_bin' is not valid for CHARACTER SET 'utf8'
SELECT a.*
FROM mood_question_dataset_definitions a, mood_question_datasets b
WHERE a.id = b.datasetdefinition AND a.type = '1' AND b.question = ? AND a.name COLLATE utf8mb4_bin = ?
[array (
0 => '16',
1 => 'x',
)]
Error code: dmlreadexception
×Stack trace:
  • line 486 of /lib/dml/moodle_database.php: dml_read_exception thrown
  • line 1216 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
  • line 1571 of /lib/dml/moodle_database.php: call to mysqli_native_moodle_database->get_records_sql()
  • line 1492 of /question/type/calculated/questiontype.php: call to moodle_database->get_record_sql()
  • line 1139 of /question/type/calculated/questiontype.php: call to qtype_calculated->dataset_options_from_database()
  • line 523 of /question/type/calculated/questiontype.php: call to qtype_calculated->dataset_options()
  • line 639 of /question/type/calculated/questiontype.php: call to qtype_calculated->preparedatasets()
  • line 264 of /question/question.php: call to qtype_calculated->save_question()

Can anyone inform me about what to do? Thanks!

Average of ratings: -
In reply to Stuart Jones

Re: Calculated Question Database error

by Stuart Jones -

After trying again today, this is still a problem. It's very frustrating.

In reply to Stuart Jones

Re: Calculated Question Database error

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hi Stuart,

"Debug info: COLLATION 'utf8mb4_bin' is not valid for CHARACTER SET 'utf8'"

Looks like your database defaults might not be set correctly: https://docs.moodle.org/34/en/Installation_quick_guide#Create_a_database

Create a database

  • Using your chosen database server, create a new empty database. The default encoding must be UTF8. For example, using MySQL:
CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
For instance, the [mysqld] section of my configuration file for maridb is set like so:

[mysqld]
character-set-server  = utf8
collation-server      = utf8_general_ci
character_set_server   = utf8
collation_server       = utf8_general_ci
If you look at your database with something like phpMyAdmin, you can see what the database and each of the tables is set up to use.