could not find course/ could not find top level course/ could not find course category

Could not find course category

If you get this error (could not find course category) this basically means the course/s that exist don't have categories in the category table.

Look at the mdl_course table in mysql. Column 2 is the course category. Every course listed (per row) must have a category identified in the table mdl_course_categories.

For example, if you have this as your data

(1, 0, 0, "course name", "course name", "", "summary", 0, "site", 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", "", 1606214720, 1606215795, 0, 0, 0, 1606215383);

You see the course category is zero.

But there is a course category number one in the mdl_course_categories table:

1 | Miscellaneous | NULL     | NULL        |                 0 |      0 |     10000 |           0 |       1 |          1 |   1606214720 |     1 | /1   | NULL  |


If there is a mismatch, correct it, e.g. by updating the course to belong to the category.

Update mdl_course set category = '1' where format = 'site' and id = 1;

https://moodle.org/mod/forum/discuss.php?d=150439


Could not find top-level course

This means that mdl_course is empty. Type/copy/paste this:

 insert into mdl_course (id, category, sortorder, fullname, shortname, idnumber, summary,  summaryformat, format, showgrades, newsitems, startdate, enddate, relativedatesmode, marker, maxbytes, legacyfiles, showreports, visible, visibleold, groupmode, groupmodeforce, defaultgroupingid, lang, calendartype, theme, timecreated, timemodified, requested, enablecompletion, completionnotify, cacherev)

     values

     (1, 1, 0, "name", "name", "", "summary", 0, "site", 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, "en", "", "", 1606214720, 1606215795, 0, 0, 0, 1606215383);

That should create a course, but you still have to set its category.

 insert into mdl_course_categories  (id,name,idnumber,description,descriptionformat,parent,sortorder,coursecount,visible,visibleold,timemodified,depth,path,theme ) values (1,"Miscellaneous",1,"Misc",0,0,10000,0,1,1,1606214720,1,"/1",NULL);



make sure you have course format options:

select * from mdl_course_format_options;

+----+----------+--------+-----------+-------------+-------+

| id | courseid | format | sectionid | name        | value |

+----+----------+--------+-----------+-------------+-------+

|  1 |        1 | site   |         0 | numsections | 1     |

+----+----------+--------+-----------+-------------+-------+


if not, insert them using the same syntax. 

Insert into tablename (column1,column2,...) values (value1,value2...);

If the above does not work and it repeats the error, try re-issuing the long SQL statement but give values (1,1,1 ... if that doesn't work, try 0,0,1, or 0,1,1 or 1,0,0 etc... till you find out which combination works. It's basically trying to find its default course.


Popular posts from this blog

migrating moodle from one server to another

installing moosh to make your life easier