2.6.1+ Please help me understand this error code

2.6.1+ Please help me understand this error code

by Wendi Daniels -
Number of replies: 19

This is so frustrating, it is just one thing after another. I don't alter the code, and I get error codes that were not there before. How can I tell if someone hacking my site?

 

Here are the codes I most recently got, after submitting a quiz

*************************************************************

Can not find data record in database table quiz_attempts.

More information about this error

Debug info: SELECT * FROM {quiz_attempts} WHERE id = ?
[array (
0 => 2,
)]
Error code: invalidrecord
Stack trace:
  • line 1390 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
  • line 1366 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
  • line 490 of /mod/quiz/attemptlib.php: call to moodle_database->get_record()
  • line 508 of /mod/quiz/attemptlib.php: call to quiz_attempt::create_helper()
  • line 49 of /mod/quiz/processattempt.php: call to quiz_attempt::create()
Average of ratings: -
In reply to Wendi Daniels

Re: 2.6.1+ Please help me understand this error code

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

It sounds like you are having database issues.  Perhaps a problem with permissions.  Hard to tell without knowing the history and other errors you have run into.

In reply to Wendi Daniels

Re: 2.6.1+ Please help me understand this error code

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

That error message would only appear if you were navigating around and attempt at the quiz with $cm->id = 2, and Moodle could not find the row with id = 2 in the course_modules table.

And that cannot happen in the normal course of events, because when a quiz is deleted, all the attempts are deleted first, so if the quiz had been deleted on the Moodle course page, the error would be about not finding the record in the quiz_attempts table.

As Emma suggests, are you sure your database is running properly. (e.g. http://docs.moodle.org/26/en/How_to_check_your_database_for_corruption )

In reply to Tim Hunt

Re: 2.6.1+ Please help me understand this error code

by Wendi Daniels -

You are correct in that the table has only id #'s 1, 3 and 4. The table tests as "OK" and trying to repair it yields no results. I try to repair anyway and it says "note : The storage engine for the table doesn't support repair" So now what do I do?

 

I hate to be so helpless, I'm just not a programmer, and I am trying very hard and making great progress with the help of this forum.

 

In reply to Wendi Daniels

Re: 2.6.1+ Please help me understand this error code

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I really don't know how your database got into that state.

(If you can work out reproducible steps to make it happen again, it is worth reporting a bug.)

Another check you can do (but again it is something more developer-y that you should need to do) is go to admin -> Development -> XMLDB editor and use the [Check foreign keys] link. That will look for problems like this (things linking to other things that don't acutally exist).

But really, I suggest you just create a new quiz, delete the old one if you can, then carry on.

In reply to Tim Hunt

Re: 2.6.1+ Please help me understand this error code

by Wendi Daniels -

Wow...I have foreign keys in several area...It goes farther than just the tests. Please advise on how to fix this...pretty please...   sad

********************************************************************************************

  • Foreign key gradeitemid on table course_modules_availability is violated by 15 out of 19 rows.
    SELECT * FROM {course_modules_availability} t1 LEFT JOIN {grade_items} t2 ON t1.gradeitemid = t2.id WHERE t1.gradeitemid IS NOT NULL AND t2.id IS NULL; 
  • Foreign key question on table question_answers is violated by 466 out of 1003 rows.
    SELECT * FROM {question_answers} t1 LEFT JOIN {question} t2 ON t1.question = t2.id WHERE t1.question <> ? AND t2.id IS NULL; (0)
  • Foreign key courseid on table grade_items_history is violated by 153 out of 179 rows.
    SELECT * FROM {grade_items_history} t1 LEFT JOIN {course} t2 ON t1.courseid = t2.id WHERE t1.courseid IS NOT NULL AND t2.id IS NULL; 
  • Foreign key categoryid on table grade_items_history is violated by 101 out of 179 rows.
    SELECT * FROM {grade_items_history} t1 LEFT JOIN {grade_categories} t2 ON t1.categoryid = t2.id WHERE t1.categoryid IS NOT NULL AND t2.id IS NULL; 
  • Foreign key userid on table files is violated by 1 out of 119 rows.
    SELECT * FROM {files} t1 LEFT JOIN {user} t2 ON t1.userid = t2.id WHERE t1.userid IS NOT NULL AND t2.id IS NULL; 
  • Foreign key questionid on table qtype_multichoice_options is violated by 112 out of 245 rows.
    SELECT * FROM {qtype_multichoice_options} t1 LEFT JOIN {question} t2 ON t1.questionid = t2.id WHERE t1.questionid <> ? AND t2.id IS NULL; (0)
  • Foreign key question on table question_truefalse is violated by 36 out of 60 rows.
    SELECT * FROM {question_truefalse} t1 LEFT JOIN {question} t2 ON t1.question = t2.id WHERE t1.question <> ? AND t2.id IS NULL; (0)
In reply to Wendi Daniels

Re: 2.6.1+ Please help me understand this error code

by Wendi Daniels -

I saw another post, and I have a question...is this absolutely the result of a course i have loaded, or could it be that I played "doctor" with the ftp files? I made a lot of headway (or so I thought I did) in making the site what I needed it to be. Could that be the cause of the foreign key violations, or is there a way we could ascertain that it is IN FACT coming from the courses and tests I created?

In reply to Wendi Daniels

Re: 2.6.1+ Please help me understand this error code

by dawn alderson -

...awwwwww Wendi sounds as though you have made huge strides with the set up there!  It does now appear, that you are playing around with the quiz and what-not eh.  Joseph and co have really laid out the next steps for you....and I would suggest you follow that great advice, to be sure. smile

I would add, having read a post from Howard in another forum somewhere, today, twas a very brief and clear message: invest in a partner at least in the short term... for long term success-my interpretation of his wisdom by the way.

So, Wendi peeps are exceptionally patient here, as you will know, but it does appear there has been, over time, a decrease in a 'shared understanding' of what is going on there exactly, context is always key of course.

Hope helpful Wendi, and good luck with your exploration of the documentation and features.

warm wishes,

Dawn

 

 

 

In reply to dawn alderson

Re: 2.6.1+ Please help me understand this error code

by Wendi Daniels -

Joseph's idea was "just leave it alone and keep all the various popups and things you don't want for a couple of years", and the others helped me greatly in locating 7 foreign keys...and now I am trying to learn how to fix the foreign keys. I am working with BlueHost to try to fix them, and I have read the moodle docs. The verbiage of the foreign keys seems to indicate that it is not just the tests, and I have deleted all but 3 (there were 27 tests). All courses have been deleted but 3. I am trying to figure out how to fix those 7 keys, and following Joseph's advice means starting all over, and keeping all the things I do not want for a couple of years. I am looking for a different way.

 

Dawn, do you know how to fix these foreign keys?

In reply to Wendi Daniels

Re: 2.6.1+ Please help me understand this error code

by dawn alderson -

Wendi, hi

to be fair, Joseph has stated quite clearly that you need to investigate/play around/explore (as is) the software, with the aim of developing your knowledge and understanding for application...and that will develop over time....I agree! I am  quite sure Joseph will correct me if I am wrong. 

On that note of 'keys'-a bit of chuckle for you...the only key I know...is the one I have on a piece of string that hangs around my neck....my front door key-so as to not lose it wide eyes

cheers,

Dawn

 

 

 

 

In reply to dawn alderson

Re: 2.6.1+ Please help me understand this error code

by Wendi Daniels -

Thank you, Dawn, I appreciate your thoughts. I will continue my quest for knowledge of the foreign keys, so I don't have to start over from scratch with a website that does not run as I like. I have done a lot of work and altered a lot of things, to have only 7 foreign keys created somehow. It would take me more time to start over rather than just fix 7 keys. I just don't understand the lingo in the coding, and apparently no one else who has responded understands them either.  sad  Surely, there is someone who does, and I will fix the keys and go forward.

In reply to Wendi Daniels

Re: 2.6.1+ Please help me understand this error code

by Wendi Daniels -

Another piece of information:

 

When I go into my PHP My Admin and I click on SQL at the top and enter the table reference (after taking the curly brackets out and putting "mdl_" on the front) it shows us the lines that do not exist that one table is referencing in another table. I am reluctant to just erase these lines. I have erased all but 3 of the 27 courses and quizzes, as well as the backup files. Should I erase the lines in the PHP My Admin table that seem to not exist?

In reply to Wendi Daniels

Re: 2.6.1+ Please help me understand this error code

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Sorry, it has taken me a while to work out what to reply here.

The great advantage of open source software is that you can completely customise it to work the way you want ... if you are prepared to put in enough effort, and have the skills to do it.

That is the problem really. There is probably some trite and irritating cliche for this, like: with great power comes great responsibility.

Anyway, the point is that if you are going to tinker, you should really not change anything that you can't have a reasonable chance of tinkering back into a working state if it breaks.

Lerning to tinker safely with Moodle is a mixture of generic development skills (e.g. using version control like git to track your changse, so you can find out what they were later, and undo them) plus also Moodle-specific skills, like knowing about Moodle's debugging tools.

In terms of what these particular foreign key errors mean. Well, they are probably mostly caused by bugs in Moodle core code. Problems caused by backup and restore going wrong are the most likely thing. Normally, you can just safely ignore them, unless they seem direclty related to a problem you are having. (The extra un-linked data sitting in the database tables does not acutally do any harm, it is just evidence that something went slightly wrong in the past.)

Sorry not to be more helpful.

In reply to Tim Hunt

Re: 2.6.1+ Please help me understand this error code

by Wendi Daniels -

Thank you, Tim. I appreciate your response. I was careful, and "foreign key violations" was something I was informed about after I had changed code, so I had no way of knowing exactly what I had changed (or if it was my alterations or moodle core). Nothing was going wrong that was not fixed another way. I have been extraordinarily careful with the code, but there are things I really want changed before it goes live.

I have a question for you, if you have the time: If I simply reupload 2.6.1+ and copy config.php from the current upload to the fresh install...

1) Could that potentially resolve the problem of the foreign key violations, without having to start from scratch?

2) Would I lose any alterations I have made in the current install?

 

Thank you so much for your kindness.  :D

In reply to Wendi Daniels

Re: 2.6.1+ Please help me understand this error code

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Let us go back to fundamentals briefly: A Moodle site comprises three parts

  1. The code (often in a folder called moodle)
  2. The database
  3. The uploaded files (often in a folder called moodledata).

All the content that makes up your site is in 2) and 3). 1) Controls how that data is displayed, and how it gets updated.

So, if you wipe and reload the database, then you will lose all your content. (I think that answers your question 2.)

What you could do, is to Create a new Moodle site, and transfer the content from the old one, one course at a time, using Moodle's backup and restore. That might leave you with less junk in your database.

However, the junk in the database is not a bit worry. Let's try an analogy. Suppose you have an old lamp in a corner that is not plugged into your house's electrics. That is not going to do any harm (e.g. cause a short circuit, electrocute you, or start a fire). It is just going to take up a bit of space. The trouble will only come if you actually need to turn that lamp on. At that point, the fact it is not plugged in means it cannot work.

The error message you got originally is similar to saying that one lamp is not plugged in.

Now, if you are house proud, then you might actually want to know who left that lamp there, but that is the cause of the problem: the person who left the lamp there unplugged, not so much the lamp itself, but if it is a one-off event, it is probably not worth spending too much time on. If you want the space back, throw away the lamp.

However, it may turn out that you have a malicious child/cat/something living in your house, who delights in going round unplugging all your lamps at random time. If that is the case, then you have real ongoing problem that you need to find and fix. That would be like a software bug, but to make progress, you really need to catch them in the act to learn what is happening.

If it turn out that the lamp is really important to to you, then you could plug it in again. However, given the way the Moodle database is structured, that is more like finding the right plug and the right socket in the middle of a huge tangle of wires, mostly with incompatible plugs and extension sockets, than just plugging one lamp into the socket right next to it. (I think that answers your question 1)

[Cool! I think that analogy worked smile]

Average of ratings: Useful (4)
In reply to Tim Hunt

Re: 2.6.1+ Please help me understand this error code

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

I love this analogy Tim!  

I was actually going to ask you if you had a neat little script that would find all related entries and do a database deletion of a question but maybe I should not worry if I have a couple of thousand lamps lying around that are unplugged!  

Or should I?  

In reply to Emma Richardson

Re: 2.6.1+ Please help me understand this error code

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

That is the point of the XMLDB -> Check foreign keys script.

It tells you how many old lamps are left in each table, and gives you the SQL to find them.

It does not give you the SQL to acutally delete them. You would have to work that out on your own, but I am not sure I would recommend it.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: 2.6.1+ Please help me understand this error code

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

That's what I am going to need to decide.  I had a heck of time restoring courses into a new site.  Was really hoping to have a nice clean database after the rebuild but the question bank gave me fits and I think I probably have at least two copies of the entire bank which is several thousand entries.  I would like to be able to just go in and fully delete all the questions that are "hidden" right now but that probably has a greater chance of creating some orphaned records which would have the potential of creating more issues than a few thousand extra questions.

Feature request - when you delete a question, it would nice to have an option to fully delete it, not just set it to hidden.

In reply to Emma Richardson

Re: 2.6.1+ Please help me understand this error code

by Gordon Toudt -

Emma,  I vote for that as well.  The question database gets copied so many times that the hidden items are now outnumbering the ones in use.  Delete should be delete or at least hidden for 48 hours then deleted on the next cron run.

In reply to Tim Hunt

Re: 2.6.1+ Please help me understand this error code

by Wendi Daniels -

Wow - thanks! Someone mentioned a foreign key check, and when I saw the word "violations" I thought it was a big issue. I can't imagine the violations, although in a number that seems daunting, are really taking up too much space. The site seems unhampered by them, so this issue is done. Thank you!  smile