ERROR: Can't find data record in database table course_categories.

ERROR: Can't find data record in database table course_categories.

by Francesco Viali -
Number of replies: 3

Hi,
a collegue installed a second moodle instance for testing purpouse but he made an error using the same MoodleData directory.
After an upgrade we have this error: 

Can't find data record in database table course_categories.
Debug info: SELECT id,parent FROM {course_categories} WHERE id = ?
[array (
0 => '2',
)]
Error code: invalidrecord
Stack trace:
  • line 1562 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
  • line 1538 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
  • line 6598 of /lib/accesslib.php: call to moodle_database->get_record()
  • line 658 of /course/classes/category.php: call to context_coursecat::instance()
  • line 1191 of /course/classes/category.php: call to core_course_category::can_view_category()
  • line 1307 of /course/classes/category.php: call to core_course_category->get_not_visible_children_ids()
  • line 300 of /course/classes/category.php: call to core_course_category->get_children()
  • line 1301 of /lib/navigationlib.php: call to core_course_category::user_top()
  • line 3468 of /lib/navigationlib.php: call to global_navigation->initialise()
  • line 3513 of /lib/navigationlib.php: call to navbar->has_items()
  • line 4489 of /lib/outputrenderers.php: call to navbar->get_items()
  • line 44 of /theme/boost/layout/columns2.php: call to core_renderer->region_main_settings_menu()
  • line 1374 of /lib/outputrenderers.php: call to include()
  • line 1304 of /lib/outputrenderers.php: call to core_renderer->render_page_layout()
  • line 100 of /index.php: call to core_renderer->header()

Reading forum I tried this:

SELECT * FROM mdl_course c WHERE NOT EXISTS (SELECT 1 FROM mdl_context ctx WHERE ctx.instanceid = c.id AND ctx.contextlevel = 50)

and  query return no rows


I also tried:

SELECT *

FROM mdl_context ctx

LEFT JOIN mdl_context parent ON ctx.path LIKE CONCAT('%/', parent.id, '/', ctx.id)

WHERE parent.id IS NULL OR ctx.path <> CONCAT(parent.path, '/', ctx.id)


and query returns one row with contextlevel = 10

Any suggestion?

Average of ratings: -
In reply to Francesco Viali

Re: ERROR: Can't find data record in database table course_categories.

by Ken Task -
Picture of Particularly helpful Moodlers

A clone of production is only as good/useful depending upon how one plans to use the clone.  Strongly suggest setting the cloned site to 'nomail ever' just in case notifications/forums or something/anything involving email to users won't be sent inadvertently (confuses students/teachers).

Eventually, user accounts might expire in the clone, usage is not as much so data depicting events, etc. old etc.

So when it becomes not so useful, one will be cloning again.

So ... suggest cloning again ... this time with a unique/matching moodledata for the clone site.   Good practice as if one tinkers a lot with plugins/etc the clone might become useless.

However, since it is a clone ... and a tinker toy ... the 'easiest fix' for the clone might be to simply clone the production moodledata directory to something unique for the clone to use (changing the clone config.php file to point to the new) - even though it might not match everything in it's moodledata/filedir/

That in itself will serve a purpose in that you will see what happens if migrating site and one didn't migrate moodledata ...

My 2 cents of course!

'SoS', Ken


In reply to Francesco Viali

Re: ERROR: Can't find data record in database table course_categories.

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Is the error on the live site or the development site?  And which site did you upgrade?

In reply to Emma Richardson

Re: ERROR: Can't find data record in database table course_categories.

by Tim Widdup -
Hi, I've had this same problem too, on our test server - version 3.9.1. Do you know how to fix this issue?