error/error_question_answers_missing_in_db

Re: error/error_question_answers_missing_in_db

by Sam Alexander -
Number of replies: 4

I had this same issue.  After some investigation I found out leading and trailing spaces in some answers in the question bank were causing the error.  You can see if you have any problem answers by using a MySQL query.  Here is the one I used to find the problem database entries:

SELECT answer FROM `mdl_question_answers` WHERE answer LIKE " %" OR "% ";

Note - the syntax is "<space>%" OR "%<space>"

If there are any answers in the mdl_question_answers table that have a leading or trailing space, you can clean them up with the following UPDATE command using TRIM:

UPDATE mdl_question_answers SET answer = TRIM(answer) WHERE answer LIKE " %" OR "% ";

After cleaning them up I was able to import between classes without errors.

Hope this alleviates your problem.

 

Sam Alexander

In reply to Sam Alexander

Re: error/error_question_answers_missing_in_db

by Giancarlo De Pol -

Hi,same issue here, 2.6.1. I can see the culprit questions by turning on Debug->Developer, they show up during Restore; the process hangs and the log shows e.g.

Error code: error_question_answers_missing_in_db
$a contents: stdClass Object
(
[filequestionid] => 18278
[dbquestionid] => 69659
[answer] => 10 N
)

they all have leading or trailing spaces, as Sam Alexander says, here there's an extra space in front of "10 N". I don't think I can use your solution from within MOODLE as administrator, so I'm chasing them one by one, which is lengthy. Is there a way I can find the question, knowing the "filequestionid" provided by the log? I mean, find where the question is in the categories, so I can edit it and drop the extra spaces?

Thanks, Giancarlo

In reply to Giancarlo De Pol

Re: error/error_question_answers_missing_in_db

by Sam Alexander -

Giancarlo,

The only way I figured to do that was through MySQL. See if you can find someone that knows MySQL and can run the command I gave earlier. I ran it from the web based administration tool phpMyAdmin.  I hope this helps.

Sam Alexander

In reply to Giancarlo De Pol

Re: error/error_question_answers_missing_in_db

by Josef Kovar -

Hello,
teachers have a problem with copying tests. When you try to create a copy of the test using the "Duplicate" error appears : error_question_answers_missing_in_db (see printscren).
error/error_question_answers_missing_in_db
Debug info: Error code: error_question_answers_missing_in_db $a contents: stdClass Object ( [filequestionid] => 23002 [dbquestionid] => 23016 [answer] => Norsko )
* line 185 of /backup/moodle2/restore_qtype_plugin.class.php: restore_step_exception thrown
* line 137 of /backup/util/plan/restore_structure_step.class.php: call to restore_qtype_plugin->process_question_answer()
* line 103 of /backup/util/helper/restore_structure_parser_processor.class.php: call to restore_structure_step->process()
* line 151 of /backup/util/xml/parser/processors/grouped_parser_processor.class.php: call to restore_structure_parser_processor->dispatch_chunk()
* line 91 of /backup/util/helper/restore_structure_parser_processor.class.php: call to grouped_parser_processor->postprocess_chunk()
* line 148 of /backup/util/xml/parser/processors/simplified_parser_processor.class.php: call to restore_structure_parser_processor->postprocess_chunk()
* line 92 of /backup/util/xml/parser/processors/progressive_parser_processor.class.php: call to simplified_parser_processor->process_chunk()
* line 190 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser_processor->receive_chunk()
* line 278 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->publish()
* line ? of unknownfile: call to progressive_parser->end_tag()
* line 179 of /backup/util/xml/parser/progressive_parser.class.php: call to xml_parse()
* line 158 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->parse()
* line 110 of /backup/util/plan/restore_structure_step.class.php: call to progressive_parser->process()
* line 181 of /backup/util/plan/base_task.class.php: call to restore_structure_step->execute()
* line 177 of /backup/util/plan/base_plan.class.php: call to base_task->execute()
* line 167 of /backup/util/plan/restore_plan.class.php: call to base_plan->execute()
* line 333 of /backup/controller/restore_controller.class.php: call to restore_plan->execute()
* line 3507 of /course/lib.php: call to restore_controller->execute_plan()
* line 3434 of /course/lib.php: call to duplicate_module()
* line 118 of /course/rest.php: call to mod_duplicate_activity()
What should I do? Is there any solution ? Please help.

Best regards,
Josef Kovar
Metropolitan university Prague

Attachment error_question_answers_missing_in_db.JPG
In reply to Sam Alexander

Re: error/error_question_answers_missing_in_db

by Michael Brown -

I had to modify your SQL a little bit for this to detect spaces at the end of answers but after that it worked fine.


SELECT answer FROM `mdl_question_answers` WHERE answer LIKE " %" OR answer LIKE "% ";

UPDATE mdl_question_answers SET answer = TRIM(answer) WHERE answer LIKE " %" OR answer LIKE "% ";