Can't find data record in database table course

Can't find data record in database table course

by Lynn Daley -
Number of replies: 3

 Moodle 3.9+ (Build: 20200626)

PHP 7.3.21

CentOS

I am trying to add a couple of new activities to the course completion list but when I go to the activity completion page I get the following error.

Can't find data record in database table course.

I turned on developer debugging and it said:

Status Not yet started
Required All criteria below are required
Can't find data record in database table course.
More information about this error
Debug info: SELECT id,category FROM {course} WHERE id IS NULL
[array (
)]
Error code: invalidrecord
Stack trace:
    •    line 1599 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
    •    line 1575 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
    •    line 6928 of /lib/accesslib.php: call to moodle_database->get_record()
    •    line 218 of /completion/criteria/completion_criteria_course.php: call to context_course::instance()
    •    line 186 of /blocks/completionstatus/details.php: call to completion_criteria_course->get_details()

Any help in fixing this would be gratefully received.

I've already tried running cron 10-15 times to run the clean up tasks but that didn't help.

Average of ratings: -
In reply to Lynn Daley

Re: Can't find data record in database table course

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I think this is a bug...

You need to edit the database to fix it. Look at table mdl_course_completion_criteria. Find any records where 'course' is your courseid and 'module' is null. Delete these records.

You should really take a full DB backup first.
In reply to Howard Miller

Re: Can't find data record in database table course

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

This might be MDL-68715 which was fixed in 3.9.1 (Build: 20200713) so I'd certainly suggest updating to the latest weekly release. This should perform the database fix too.

Average of ratings: Useful (1)
In reply to Leon Stringer

Re: Can't find data record in database table course

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Yep, it sounds like it. An even better idea in that case!