Note: You are currently viewing documentation for Moodle 2.2. Up-to-date documentation for the latest stable version is available here: error/moodle/error question answers missing in db.

error/moodle/error question answers missing in db

From MoodleDocs
Revision as of 03:52, 19 June 2012 by Chris Egle (talk | contribs) (Created page with "This error means that you have records in your '''mdl_question_answers''' table that no longer have a matching question in the '''mdl_question''' table. Here's a way to find the...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This error means that you have records in your mdl_question_answers table that no longer have a matching question in the mdl_question table. Here's a way to find them in MySQL (other databases may have a slightly different syntax):

SELECT mdl_question.id, mdl_question_answers.id, mdl_question_answers.question FROM mdl_question_answers

Left Join mdl_question ON mdl_question_answers.question = mdl_question.id

WHERE mdl_question.id IS NULL


I highly recommend that you make a copy of the mdl_question_answers table before you start deleting records.

Here's a way to delete those orphaned rows in the mdl_question_answers:

DELETE mdl_question_answers.* FROM mdl_question_answers LEFT JOIN mdl_question ON mdl_question_answers.question = mdl_question.id WHERE mdl_question.id IS NULL