Hi all,
After upgrading from 1.9 to 2.2, some of my courses will not load. I get the message:
If you run cron once, it should sort out the mess.
Hi,
I have run cron as you suggested but it has not made any difference. Any other thoughts?
Oh sorry, the key bit of cron only runs about 20% of the time.
I shoudl ahve said: "Run cron about 5 or 10 time, until you see a message like "Running clean-up tasks..." near the top of the ouptut
Hi Mate,
I have run cron over 10 times now and still got the same issue. Any ideas?
I really thought that would fix it.
If you want to investigate further, you will probably need to investigate in the DB. For example try queries like
SELECT * FROM mdl_course c WHERE NOT EXISTS (SELECT 1 FROM mdl_context ctx ON ctx.instanceid = c.id AND ctx.contextlevel = 50)
That will find any courses where the course context does not exist (so it should return 0 rows).
You can also do similar queries for modules and blocks
SELECT * FROM mdl_course_modules cm WHERE NOT EXISTS (SELECT 1 FROM mdl_context ctx WHERE ctx.instanceid = cm.id AND ctx.contextlevel = 70)
SELECT * FROM mdl_block_instances bi WHERE NOT EXISTS (SELECT 1 FROM mdl_context ctx WHERE ctx.instanceid = bi.id AND ctx.contextlevel = 80)
If all those quries return no rows, then I am really confused by the error you are seeing.
Hi Tim,
I have installed phpmyadmin to run the commands.
When I try the first one you listed I get the following error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ON ctx.instanceid = c.id AND ctx.contextlevel = 50) LIMIT 0, 30' at line 1
Sorry, that was a copy-and-paste error.
SELECT * FROM mdl_course c WHERE NOT EXISTS (SELECT 1 FROM mdl_context ctx WHERE ctx.instanceid = c.id AND ctx.contextlevel = 50)
No worries.
Using the new line it says: MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0022 sec )
If I change the end of the statement to AND ctx.contextlevel = 100 it then shays: Showing rows 0 - 29 ( 91 total, Query took 0.0010 sec)
Not really sure what that means though!
I have changed contextlevel to 70 assuming that's the level within courses and get a number of rows returned. How do I re link them?
Zero rows is correct, and what I would expect. What about the other queries above, relating to modules and blocks?
All 3 of the queries you provided return 0 rows mate.
But if I actually look in the context table - assuming I am looking in the right place; I can't see the missing courses.
Any more thoughts?
Not really. I suppose you could try setting Debugging to DEVELOPER level, to see if that gives a more informative error message. If it does, copy and paste the whole thing here.
Here is an output from one of the broken links when developer level debugging is enabled:
Can not find data record in database table context.
Ah, I see. The problem is in get_parent_contexts, which means that the problem is with the path for one of your contexts. (I wish I had thougth to start by asking for the full debug output! Sorry.)
So, can we do a query to locate that particular problem?
OK, try this
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)
If everything is OK, that query will return one row with contextlevel = 10, but in your case it should return more.
This is the output:
Showing rows 0 - 7 ( 8 total, Query took 6.4536 sec)
id | contextlevel | instanceid | path | depth | id | contextlevel | instanceid | path | depth |
---|---|---|---|---|---|---|---|---|---|
1 | 10 | 0 | /1 | 1 | NULL | NULL | NULL | NULL | NULL |
44 | 50 | 5 | /1/491/3496/492/493/570/44 | 7 | NULL | NULL | NULL | NULL | NULL |
215 | 50 | 8 | /1/491/3496/492/493/571/215 | 7 | NULL | NULL | NULL | NULL | NULL |
392 | 50 | 10 | /1/491/3496/492/493/570/392 | 7 | NULL | NULL | NULL | NULL | NULL |
961 | 50 | 16 | /1/491/3496/492/493/570/961 | 7 | NULL | NULL | NULL | NULL | NULL |
1474 | 50 | 21 | /1/491/3496/492/493/570/1474 | 7 | NULL | NULL | NULL | NULL | NULL |
1590 | 50 | 26 | /1/491/3496/492/493/570/1590 | 7 | NULL | NULL | NULL | NULL | NULL |
1775 | 50 | 34 | /1/491/3496/492/493/570/1775 | 7 | NULL | NULL | NULL | NULL | NULL |
I assume that output is what you expected. Is there a fix for it?
Right, so the problem is those paths. The bits of teh path are context ids, so can you check whether contexts 491, 3496, 492, 493, 570 and 571 exist? Actually, just do
SELECT * FROM mdl_context WHERE id IN (491, 3496, 492, 493, 570, 571)
and then we should have enough information to get this fixed.
Here is the output:
Showing rows 0 - 2 ( 3 total, Query took 0.0006 sec)
![]() | id | contextlevel | instanceid | path | depth | ||||
---|---|---|---|---|---|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
491 | 40 | 2 | /1/491 | 2 | |
![]() |
![]() |
![]() |
![]() |
492 | 40 | 3 | /1/491/3496/492 | 4 | |
![]() |
![]() |
![]() |
![]() |
3496 | 40 | 21 | /1/491/3496 | 3 |
OK, so you are missing contexts 493, 570, 571 which should correspond to the categories that the problem courses are in. Or perhaps the categories got deleted somehow, but the courses are still there.
I think the easiest way to fix this up is to use a simple script to move these courses into a category that we know is OK.
If you are wise, you will take a backup of everything before going any further.
Save the following script into a file called fixup.php using a plaing text editor.
Upload it to the root folder of your Moodle site (the same folder that contains files colled config.php and pluginfile.php) then visit the URL .../fixup.php with your web browser. Hopefully it will work, but I have to say this is just my best guess. It might be a good idea to set Debugging to developer level before running the script.
The alternative is to read the code, and work out exactly what the move_courses function does, and do the same thing manually in the database. That is more complex, but might be a bit safer.
<?php
require_once('config.php');
require_once($CFG->dirroot . '/course/lib.php');
require_login();
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
move_courses(array(5, 8, 10, 16, 21, 26, 34), 3);
echo 'Done!';
Hi Tim,
That seems to have worked a treat!
The courses now appear when clicked on. Can't see any adverse effects at the moment but will check through all the courses to be sure.
Thanks very much for your help - I reall appreciate it!
Could I call upon you one more time?
I have a new problem that came up earlier today HERE. Any thoughts on this one?
Actually don't worry about the other problem - managed to sort it!
Thanks very much again for all your help!
Thanks Tim / Thanks Richard,
I got the same issue and its been resolved now by following all the steps. But one critical issue, I can see all the courses, but courses are empty, I have lost all the course data (forums, resources, activities etc.)
Any suggestion on that Moodle data directory contains the data but Moodle is not showing that.
Please suggest what to do.
Thanks,
Jaswant
Just by guessing without looking at the error,
perhaps the issue might be: (I'm just guessing)
1. in your config.php file, make sure its
$CFG->wwwroot ='http://moodlewebsite.org';
pointing to the right url and folder,
OR
$CFG->dataroot ='/home2/jpaccart/public_html/moodledata';
make sure its pointing to the right database, If the courses are empty than its pointing to a different database, the moodle system is retrieving empty database....
which you might check this two lines...
$CFG->dbname ='xxxxxxx';
$CFG->dbuser ='xxxxxxx';
Sometimes the prefix also has changed,
$CFG->prefix ='mdl_'
check this also,
Sorry if this might not solve your problem, than I'm pretty sure it has to do with the Moodle system communication with the Database....may be others could help.....
I had the same problem just now. I found that I could move the courses to a different category under Site Administration > Manage courses and categories and then back to the original category. That fixed the problem.
Tim, I get this error when trying to view a quiz record from the logs. Is it the same sort of problem do you think? I ran Cron some 14 times and cleared the cache and still get the error.
Running Moodle 2.6.5+
Nathan
Hi TIM, i have same problem, and your explanation has been very reassuring.
But, in my case the Select:
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)
I've tried several times
How can I know which are the contexts that might be failing and that I should correct with the scriptHi Tim,
I know this thread is to old to add query here.. still i though of trying my luck..
I faced same problem while accessing dashboard.. I can access other pages.. but only dashboard is not working.
Debug info: SELECT * FROM {context} WHERE id = ?
[array (
0 => '66',
)]
Error code: invalidrecord
I tried the query which you have mentioned here
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)
Output:
id | contextlevel | instanceid | path | depth | id | contextlevel | instanceid | path | depth |
1 | 10 | 0 | /1 | 1 |
Hello Tim , how i can debug my project for get more information, I did the previous step and my phpmyadmin gave back : "MySQL returned an empty result set (i.e. zero rows). (Query took 0.0004 seconds.)" what can i do for debug and to obtain like Richard Lian.
This is a very old thread. Please start a new one and then tell us exactly what problem you are having and we will try to help.
I get this error when I type localhost:98/EnglishClassPlus
Can not find data record in database table course_modules.
Could not trace the error. Please help
The problem is solved. Thank you.
Its just a line of code that I have added to the layout of my theme.
What was the line of code you added to make it work? you could share with us?
I experienced this exact same error today. The way I fixed it was to move the problematic course out of the category it was in, using the Moodle interface, and into a different category. I then moved it back into the original category and the course displayed correctly. This action must have forced Moodle to create the missing context entries in the DB.
I'm pretty sure this error was caused by deleting some sub-categories.
Hope this helps other with the same issue.
Marty
P.S. Thanks to all who contributed to this thread, it allowed me to diagnose the problem very quickly.
we are experiencing a similar error but in the course_modules :
Can not find data record in database table course_modules.
Debug info: SELECT id,course FROM {course_modules} WHERE id = ? [array ( 0 => '39683', )]
Error code: invalidrecord Stack trace:
we have run the cron script several times but has not fixed the error, also tried moving the course to another category
fixed it with
update mdl_course set modinfo='' where id = 10024;
I'm getting a similar error when I want to load a SCORM.
Only happens in one course, other courses are ok.
Just to be explicit-
id is the course id number, which you can see in the url:
Hi, i have this problem for course table:
'Can not find data record in database table course.'
none of this answers have effect on result.
please help me!
thanks in advanced.
I have same problem.
please any one give perfect solution for this error.
thank you
Just experienced this issue in Moodle v2.4.6
I was working in the course categories view and suspect I may have caused the problem* by doing one of the following. In the situation where I had:
Category A
Category B
Category C
Category D
- With Categories B and C both empty, I deleted Category B without first deleting Category C.
- With a different set of categories, but in a similar arrangement, I moved Category C from under Category B to Category D
Thanks to the tips provided by participants in this thread, I fixed the problem by creating a new category structure and used the Moodle interface to move the courses to the new categories.
* When I have a moment, I'll go back and test my theory on our sandbox instance and report the results back here and to the Moodle Tracker.
Hrynkiw
Kwantlen Polytechnic
Thanks to the tips provided
I fixed the problem by creating a new category structure and used the Moodle interface to move the courses to the new categories.
I kept miscellany and created a category at the same level
Hello,
I am having the exact same problem when upgrading from Moodle 2.3 to either 2.4 or 2.5. There are two courses that I can no longer access, though the do appear to be in the database.
I tried the SQL query Tim suggested and only had the one row returned with contextlevel = 10 so it isn't the same issue, just similar. Can someone please help me find the proper SQL query I need to find the error?
Here is the stack trace for one of the courses:
Can not find data record in database table course.
Hi, I have the same problem with Moodle 2.5 - Dataform. When I try to add and element to the Dataform module, I got "Can not find data record in database table course_modules." It then redirects me to this page.
Any help with this error for our Moodle 2.5 admin ?
Best, Miro
Me to, here is the debug form Moodle 2.5+ (Build: 20130627)
Strict Standards: Creating default object from empty value in /var/www/moodle/report/log/index.php on line 107
Coding problem - missing course modinfo property in get_fast_modinfo() call
line 1384 of /lib/modinfolib.php: call to debugging()
line 1803 of /lib/navigationlib.php: call to get_fast_modinfo()
line 1870 of /lib/navigationlib.php: call to global_navigation->generate_sections_and_activities()
line 420 of /course/format/lib.php: call to global_navigation->load_generic_course_sections()
line 1782 of /lib/navigationlib.php: call to format_base->extend_course_navigation()
line 1093 of /lib/navigationlib.php: call to global_navigation->load_course_sections()
line 3178 of /lib/navigationlib.php: call to global_navigation->initialise()
line 717 of /lib/pagelib.php: call to settings_navigation->__construct()
line 734 of /lib/pagelib.php: call to moodle_page->magic_get_settingsnav()
line 6348 of /lib/adminlib.php: call to moodle_page->__get()
line 150 of /report/log/index.php: call to admin_externalpage_setup()
Coding problem - missing course sectioncache property in get_fast_modinfo() call
line 1388 of /lib/modinfolib.php: call to debugging()
line 1803 of /lib/navigationlib.php: call to get_fast_modinfo()
line 1870 of /lib/navigationlib.php: call to global_navigation->generate_sections_and_activities()
line 420 of /course/format/lib.php: call to global_navigation->load_generic_course_sections()
line 1782 of /lib/navigationlib.php: call to format_base->extend_course_navigation()
line 1093 of /lib/navigationlib.php: call to global_navigation->load_course_sections()
line 3178 of /lib/navigationlib.php: call to global_navigation->initialise()
line 717 of /lib/pagelib.php: call to settings_navigation->__construct()
line 734 of /lib/pagelib.php: call to moodle_page->magic_get_settingsnav()
line 6348 of /lib/adminlib.php: call to moodle_page->__get()
line 150 of /report/log/index.php: call to admin_externalpage_setup()
Notice: Undefined property: stdClass::$format in /var/www/moodle/course/format/lib.php on line 171
Format plugin format_ is not found. Using default format_topics
line 118 of /course/format/lib.php: call to debugging()
line 179 of /course/format/lib.php: call to format_base::get_format_or_default()
line 35 of /course/format/lib.php: call to format_base::instance()
line 1807 of /lib/navigationlib.php: call to course_get_format()
line 1870 of /lib/navigationlib.php: call to global_navigation->generate_sections_and_activities()
line 420 of /course/format/lib.php: call to global_navigation->load_generic_course_sections()
line 1782 of /lib/navigationlib.php: call to format_base->extend_course_navigation()
line 1093 of /lib/navigationlib.php: call to global_navigation->load_course_sections()
line 3178 of /lib/navigationlib.php: call to global_navigation->initialise()
line 717 of /lib/pagelib.php: call to settings_navigation->__construct()
line 734 of /lib/pagelib.php: call to moodle_page->magic_get_settingsnav()
line 6348 of /lib/adminlib.php: call to moodle_page->__get()
line 150 of /report/log/index.php: call to admin_externalpage_setup()
Skip to main content
I have tried Tims fix and done multipal manual runs on cron.php
We did an upgrade from 2.7.x to 2.8.1, and everything looked fine. Tested out fine on our dev server, and a smooth upgrade on production.
However, we've now heard from students who can't access their courses. Other roles (admin, teacher, a custom librarian role based off of teacher) have no problems.
Students with access issues get the message: "Can not find data record in database table course".
Affected courses have all students locked out. Other courses in the same category don't have a problem.
We're using the Banner LMB enrollment plugin for the current semester, so I thought it might be related to that. But there are past semester courses that were batch enrolled using the manual enrollment process that are also affected.
Does this seem to be the same context issue reported here? Thanks.
It looks like it might be an issue with the attendance plugin.
Hi Keith,
We're experiencing this issue only with the auto attendance mod/block if that's helps. After the upgrade our site works fine and all the courses load ok, we get the "Can not find data record in database table context" message only in relation to the attendance module.
You need to enable debugging to see where this error refers to, it debug information would tell you from where it comes.
But would be nice if someone (maybe a developer?) who knows could shed some light on how this context generic message is being triggered and what might be the source of problem. Just a bit of help to investigate further..
I disabled both the attendance activity module and the related attendance block, and student access to courses has been restored.
It sounds as though the maintainer of the attendance activity is aware of the problem and working on an update, so hopefully there will be a new module and block to install shortly.
Is the problem with both the activity module and the block, or just with the block? Thanks.
I had this problem going from 2.6.4 to 3.3.2 - I installed the cronjob and let it run every 15 minutes.
Woke up the next day and it fixed itself :D
Hi All,
I upgraded the moodle 3.3 to 3.4 and it shows this "invalid Record" error. I doesn't allow me to enrol users
I enable the debugging mode and now it shows error with details.
Error code: servicenotavailable * line 214 of \lib\externallib.php: moodle_exception thrown * line 59 of \lib\ajax\service.php: call to external_api::call_external_function() Error code: servicenotavailable * line 214 of \lib\externallib.php: moodle_exception thrown * line 59 of \lib\ajax\service.php: call to external_api::call_external_function()
Regards,
Peshali
Hi Peshali
Looks like that issue has been addressed here: https://tracker.moodle.org/browse/MDL-56896
I get it in Moodle 3.5 as well.