Error writing to database when Creating and Deleting Courses

Error writing to database when Creating and Deleting Courses

Russell Myers -
回帖数:13

We recently upgraded moodle to version 2.0 (Build: 20101125). We thought it went ok, but we had not tried to create a new course. When our teachers went to create a new course, they would get errors (Error writing to database). I would get them deleting the courses too.

I turned on debugging and get this error when creating a course:

Debug info: Duplicate entry '26-20000' for key 2

UPDATE mdl_course

SET sortorder = ((sortorder) % (10000)) + ?

WHERE category = ?

[array (

0 => '20000',

1 => '26',

)]

Stack trace:

  • line 394 of /lib/dml/moodle_database.php: dml_write_exception thrown
  • line 672 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
  • line 1061 of /lib/datalib.php: call to mysqli_native_moodle_database->execute()
  • line 3592 of /course/lib.php: call to fix_course_sortorder()
  • line 111 of /course/edit.php: call to create_course()

 

When deleting the course I get:

Debug info: Duplicate entry '26-20001' for key 2

UPDATE mdl_course

SET sortorder = sortorder + 1

WHERE category = ?

[array (

0 => '26',

)]

Stack trace:

  • line 394 of /lib/dml/moodle_database.php: dml_write_exception thrown
  • line 672 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
  • line 1090 of /lib/datalib.php: call to mysqli_native_moodle_database->execute()
  • line 74 of /course/delete.php: call to fix_course_sortorder()

We are running Moodle on 10.5 OS X web server and Ubuntu mysql server. Can anyone suggest the next test for me or a path to fix these issues?

 

Thanks

回复Russell Myers

Re: Error writing to database when Creating and Deleting Courses

Dmitrii Zaharov -

Same error. Can't find the solution 伤心

Debug info: Duplicate entry '38-129999' for key 2
UPDATE mdl_course SET category = ?,sortorder = ? WHERE id=?
[array (
0 => '38',
1 => 129999,
2 => '88',
)]
Stack trace:
  • line 394 of /lib/dml/moodle_database.php: dml_write_exception thrown
  • line 980 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
  • line 1012 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->update_record_raw()
  • line 3400 of /course/lib.php: call to mysqli_native_moodle_database->update_record()
  • line 100 of /course/category.php: call to move_courses()
回复Russell Myers

Re: Error writing to database when Creating and Deleting Courses

Kim Scannell -
I am also having this issue in 2.0.2 -- getting an 'error writing to database' message, although the courses are actually being created (or deleted as the case may be).

However, a newly created course creates a sort order number duplicate. A newly created course is assigned sortorder 0 in the course table in the database. Creating a second course in that category is also assigned sort order 0, creating a conflict.

Courses can be moved between categories, but sort order doesn't change when moving a course within a category. The up/down arrow gives the writing to database error.

These new courses appear at the top of the list in the category. They used to (in 1.9) appear at the bottom of the list.

Oddly, I see this issue was reported for 1.9, but my installation did not have this quirk in 1.9, but it is now since we upgraded to 2.0.2 (PhP 5.2.16, MySQL 5.1.52).

Also, I don't know if this is related to the sort order thing, but Manual enrollment is the default for my site, but it is not being applied to new courses upon creation.

I am fixing these things manually as they occur, so it's not that big a deal for me, but any ideas or quick fixes would be appreciated.
Thanks.


回复Kim Scannell

Re: Error writing to database when Creating and Deleting Courses

Freyr Gunnar Ólafsson -

I think I might have the same issue.

Debug info: Duplicate entry '13-20021' for key 'category_sortorder'
UPDATE mdl_course
SET sortorder = sortorder + 1
WHERE category = ?
[array (
0 => '13',
)]
Stack trace:

 *   line 394 of /lib/dml/moodle_database.php: dml_write_exception thrown
 *   line 703 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
 *   line 1095 of /lib/datalib.php: call to mysqli_native_moodle_database->execute()
 *   line 3817 of /course/lib.php: call to fix_course_sortorder()
 *   line 135 of /course/edit.php: call to update_course()
回复Freyr Gunnar Ólafsson

Re: Error writing to database when Creating and Deleting Courses

Javier Silva -

I have the same problem and had to change one by one the entries in the database and then i create a new course.

I can't sort the course yet.

回复Kim Scannell

Re: Error writing to database when Creating and Deleting Courses

Kim Scannell -
As a workaround without going into the database, I found that when I move the last course that was created (which would have sort order '0') to another category, then move it back again, it goes to the end of the list (it gets assigned something other than '0').
Then I am able to create a new course for that category and it gets assigned the '0' sort order. Repeat the category move, and I'm ready to add another course.
Sorting course order within one category, however, must still be done manually in the database.

回复Kim Scannell

Re: Error writing to database when Creating and Deleting Courses

Jeff Ottinger -

I have the same issue with restoring courses.  Apparently, when restoring a course to a new course, Moodle attempts to create the new course with a sort order of '0' which causes the restore to fail if you've also created a different course in the same category without moving it.

I'd also like to say that fixes would be appreciated.

回复Jeff Ottinger

Re: Error writing to database when Creating and Deleting Courses

Stefan Nychka -

Hi, all.

The same or a very similar bug is in the tracker:  http://tracker.moodle.org/browse/MDL-27248

Vote for it.

And, in 2.0.2, we can create and restore courses just fine.  Not sure what the difference is.  We have MySQL, Slackware Linux, although our PHP version is 5.3.16 (newer than the only, I believe, version listed here) and Apache.  I excluded all but the PHP versions for now, as they may not be relevant.

回复Russell Myers

Error writing to database when restoring Courses

Pedro Galvan -

The same happens when restoring a backup made in another moodle server, same moodle version 2.03+ on ubuntu 11.04 and apache2:

Error writing to database

More information about this error

Debug info: ERROR: null value in column "sumgrades" violates not-null constraint
INSERT INTO mdl_quiz (name,intro,introformat,timeopen,timeclose,optionflags,penaltyscheme,attempts,attemptonlast,grademethod,decimalpoints,questiondecimalpoints,review,questionsperpage,shufflequestions,shuffleanswers,questions,sumgrades,grade,timecreated,timemodified,timelimit,password,subnet,popup,delay1,delay2,showuserpicture,showblocks,course) VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30) RETURNING id
[array (
'name' => 'Whole Numbers Addition Quiz',
'intro' => '<p>Whole Numbers Addition Quiz</p>',
'introformat' => '1',
'timeopen' => '0',
'timeclose' => '0',
'optionflags' => '1',
'penaltyscheme' => '1',
'attempts' => '0',
'attemptonlast' => '0',
'grademethod' => '1',
'decimalpoints' => '2',
'questiondecimalpoints' => '-1',
'review' => '4459503',
'questionsperpage' => '1',
'shufflequestions' => '0',
'shuffleanswers' => '1',
'questions' => '',
'sumgrades' => NULL,
'grade' => '10.00000',
'timecreated' => '0',
'timemodified' => 1304606058,
'timelimit' => '0',
'password' => '',
'subnet' => '',
'popup' => '0',
'delay1' => '0',
'delay2' => '0',
'showuserpicture' => '0',
'showblocks' => '0',
'course' => 4,
)]
Stack trace:
  • line 394 of /lib/dml/moodle_database.php: dml_write_exception thrown
  • line 232 of /lib/dml/pgsql_native_moodle_database.php: call to moodle_database->query_end()
  • line 781 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->query_end()
  • line 833 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->insert_record_raw()
  • line 78 of /mod/quiz/backup/moodle2/restore_quiz_stepslib.php: call to pgsql_native_moodle_database->insert_record()
  • line 131 of /backup/util/plan/restore_structure_step.class.php: call to restore_quiz_activity_structure_step->process_quiz()
  • line 103 of /backup/util/helper/restore_structure_parser_processor.class.php: call to restore_structure_step->process()
  • line 106 of /backup/util/xml/parser/processors/grouped_parser_processor.class.php: call to restore_structure_parser_processor->dispatch_chunk()
  • line 91 of /backup/util/helper/restore_structure_parser_processor.class.php: call to grouped_parser_processor->postprocess_chunk()
  • line 132 of /backup/util/xml/parser/processors/simplified_parser_processor.class.php: call to restore_structure_parser_processor->postprocess_chunk()
  • line 92 of /backup/util/xml/parser/processors/progressive_parser_processor.class.php: call to simplified_parser_processor->process_chunk()
  • line 169 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser_processor->receive_chunk()
  • line 212 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->publish()
  • line ? of unknownfile: call to progressive_parser->start_tag()
  • line 158 of /backup/util/xml/parser/progressive_parser.class.php: call to xml_parse()
  • line 137 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->parse()
  • line 105 of /backup/util/plan/restore_structure_step.class.php: call to progressive_parser->process()
  • line 153 of /backup/util/plan/base_task.class.php: call to restore_structure_step->execute()
  • line 170 of /backup/moodle2/restore_activity_task.class.php: call to base_task->execute()
  • line 148 of /backup/util/plan/base_plan.class.php: call to restore_activity_task->execute()
  • line 157 of /backup/util/plan/restore_plan.class.php: call to base_plan->execute()
  • line 299 of /backup/controller/restore_controller.class.php: call to restore_plan->execute()
  • line 144 of /backup/util/ui/restore_ui.class.php: call to restore_controller->execute_plan()
  • line 39 of /backup/restore.php: call to restore_ui->execute()

Funny, I am not importing grades... Anyway, it restores only part of the course. I have done this before without problems in ubuntu 10.10. What am I doing wrong? How can I fix this?

回复Pedro Galvan

Re: Error writing to database when restoring Courses

Richard Ackland -

having the same issue

Debug info: Duplicate entry '31-390001' for key 2
UPDATE mdl_course
SET sortorder = sortorder + 1
WHERE category = ?
[array (
0 => '31',
)]
Stack trace:
  • line 394 of /lib/dml/moodle_database.php: dml_write_exception thrown
  • line 703 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
  • line 1095 of /lib/datalib.php: call to mysqli_native_moodle_database->execute()
  • line 3798 of /course/lib.php: call to fix_course_sortorder()
  • line 135 of /course/edit.php: call to update_course()

Moodle 2.0.3+

 

I have searched the table mdl_course for duplicate entries but can not find any...

回复Richard Ackland

Re: Error writing to database when restoring Courses

Jeff Ottinger -

You won't find any existing duplicates because the "key" in the database refuses to allow a duplicate to be made and generates the error you are getting.

回复Jeff Ottinger

Re: Error writing to database when restoring Courses

Endiku Endikux -

Has there been any progress on this issue? I have completed an upgrade and also have the same error occuring when creating, deleting or moving a course.

回复Endiku Endikux

Re: Error writing to database when restoring Courses

Curtis Barker -

I was able to almost get everything ok today.  Using the patches from:

http://tracker.moodle.org/browse/MDL-27248

and manually going through the database and changing the sort orders for any course that had a value of xxx000 (ending in 3 zeros) to something else - I used xxx100.

The only problem I still get is on restore.  Create, delete, and sort are all ok.

回复Curtis Barker

Re: Error writing to database when restoring Courses

Endiku Endikux -

Thanks for that information. It has also solved my issue. After the patches I simply went in and re-sorted the courses by name to ensure that they had new proper sort numbers. You if you had the sortorder 0 issue you can also check for 0's in the database.