"Error writing to database" when restoring course

"Error writing to database" when restoring course

by Felipe Almeida de Souza -
Number of replies: 13

Im using Moodle 3.6.3+ (Build: 20190322) and trying to restore a course from a 3.6 version. I have transfered 20 courses with no problem, but i have 5 with this "error writing to database".

Searching on the forum i discovered that is a old bug already fixed. And i already tried increase max_allowed_packet like the oficial documentation says: https://docs.moodle.org/310/en/error/moodle/dmlwriteexception

Can you guys give me a help? 

Sorry about my english, Isnt my first language.


Duplicate entry '0-0007725566-1' for key 'mdlq1_user_mneuse_uix'

INSERT INTO mdlq1_user (username,idnumber,email,icq,skype,yahoo,aim,msn,phone1,phone2,institution,department,address,city,country,lastip,picture,url,description,descriptionformat,imagealt,auth,firstnamephonetic,lastnamephonetic,middlename,alternatename,firstname,lastname,confirmed,policyagreed,deleted,lang,theme,timezone,firstaccess,lastaccess,lastlogin,currentlogin,mailformat,maildigest,maildisplay,autosubscribe,trackforums,timecreated,timemodified,trustbitmask,password) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)

[array (

0 => '0007725566-1',

1 => '',

2 => 'cintiaamelo@ig.com.br',

3 => '',

4 => '',

5 => '',

6 => '',

7 => '',

8 => '',

9 => '',

10 => '',

11 => '',

12 => '',

13 => '',

14 => '',

15 => '187.38.63.103',

16 => '0',

17 => '',

18 => '<p></p><br />',

19 => '1',

20 => '',

21 => 'manual',

22 => '',

23 => '',

24 => '',

25 => '',

26 => 'CINTIA APARECIDA ROMEIRO DE',

27 => 'MELO',

28 => '1',

29 => 0,

30 => '0',

31 => 'pt_br',

32 => '',

33 => '99',

34 => '1492469889',

35 => '1628209488',

36 => '1627221181',

37 => '1628209488',

38 => '1',

39 => '0',

40 => '2',

41 => '1',

42 => '0',

43 => '1488022500',

44 => '1622634057',

45 => '0',

46 => 'restored',

)]

Error code: dmlwriteexception

Rastreamento de pilha: 

line 489 of /lib/dml/moodle_database.php: dml_write_exception thrown

line 1357 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()

line 1403 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()

line 1245 of /backup/util/dbops/restore_dbops.class.php: call to mysqli_native_moodle_database->insert_record()

line 1147 of /backup/moodle2/restore_stepslib.php: call to restore_dbops::create_included_users()

line 34 of /backup/util/plan/restore_execution_step.class.php: call to restore_create_included_users->define_execution()

line 181 of /backup/util/plan/base_task.class.php: call to restore_execution_step->execute()

line 178 of /backup/util/plan/base_plan.class.php: call to base_task->execute()

line 168 of /backup/util/plan/restore_plan.class.php: call to base_plan->execute()

line 385 of /backup/controller/restore_controller.class.php: call to restore_plan->execute()

line 219 of /backup/util/ui/restore_ui.class.php: call to restore_controller->execute_plan()

line 143 of /backup/restore.php: call to restore_ui->execute()

Average of ratings: -
In reply to Felipe Almeida de Souza

Re: "Error writing to database" when restoring 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
"Searching on the forum i discovered that is a old bug already fixed"

Link please?
In reply to Howard Miller

Re: "Error writing to database" when restoring course

by Felipe Almeida de Souza -
In reply to Felipe Almeida de Souza

Re: "Error writing to database" when restoring 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
That's nothing to do with your problem. A different error message and different table.

I think your problem is caused by a site admin user (that isn't called 'admin') in the backup file. Although, I'm not 100% about the circumstances. In your case, what user has username '0007725566-1'??
In reply to Howard Miller

Re: "Error writing to database" when restoring course

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers
No I have come across this before - I think it is a collation issue. See here: https://moodle.org/mod/forum/search.php?id=5&search=key+%27mdl_user_mneuse_uix
About half way down, there are some solutions...
Average of ratings: Useful (1)
In reply to Emma Richardson

Re: "Error writing to database" when restoring course

by Felipe Almeida de Souza -

Unfortunately didnt worked :/
I tried:
- convert my database to barracuda;
-Change my collation to utf8mb4_unicode_ci and utf8mb4_general_ci following the "MySQL full unicode support" tutorial;
- Check the indexes (XMLDB editor -> check indexes);
And still getting the same error



In reply to Howard Miller

Re: "Error writing to database" when restoring course

by Felipe Almeida de Souza -

In all 5 courses with this error, the users showing on the debug are students

In reply to Felipe Almeida de Souza

Re: "Error writing to database" when restoring 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've seen it - I had to unpack the backup, edit the users.xml file and remove the user, repack the backup.

Yeh - I know - sorry sad
In reply to Howard Miller

Re: "Error writing to database" when restoring course

by Felipe Almeida de Souza -

Thanks!!

Unpacking, removing the user and repacking dick the trick without losing the student activities/forum posts etc.

Thank you for your time

In reply to Howard Miller

Re: "Error writing to database" when restoring course

by Felipe Almeida de Souza -
I received a few more courses to transfer from one server to another and now im getting another error:

Informações de depuração: Duplicate entry '55-0-0-0' for key 'mdlq1_assisubm_assusegroat_uix'
INSERT INTO mdlq1_assign_submission (userid,timecreated,timemodified,status,groupid,attemptnumber,latest,assignment) VALUES(?,?,?,?,?,?,?,?)
[array (
0 => 0,
1 => '1566568977',
2 => '1566568977',
3 => 'new',
4 => 0,
5 => '0',
6 => 0,
7 => 55,
)]
Error code: dmlwriteexception

From





Rastreamento de pilha:
• line 489 of /lib/dml/moodle_database.php: dml_write_exception thrown
• line 1357 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
• line 1403 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
• line 182 of /mod/assign/backup/moodle2/restore_assign_stepslib.php: call to mysqli_native_moodle_database->insert_record()
• line 137 of /backup/util/plan/restore_structure_step.class.php: call to restore_assign_activity_structure_step->process_assign_submission()
• line 121 of /backup/util/helper/restore_structure_parser_processor.class.php: call to restore_structure_step->process()
• line 178 of /backup/util/xml/parser/processors/grouped_parser_processor.class.php: call to restore_structure_parser_processor->dispatch_chunk()
• line 109 of /backup/util/helper/restore_structure_parser_processor.class.php: call to grouped_parser_processor->postprocess_chunk()
• line 148 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 190 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser_processor->receive_chunk()
• line 278 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->publish()
• line ? of unknownfile: call to progressive_parser->end_tag()
• line 179 of /backup/util/xml/parser/progressive_parser.class.php: call to xml_parse()
• line 158 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->parse()
• line 110 of /backup/util/plan/restore_structure_step.class.php: call to progressive_parser->process()
• line 181 of /backup/util/plan/base_task.class.php: call to restore_structure_step->execute()
• line 210 of /backup/moodle2/restore_activity_task.class.php: call to base_task->execute()
• line 178 of /backup/util/plan/base_plan.class.php: call to restore_activity_task->execute()
• line 168 of /backup/util/plan/restore_plan.class.php: call to base_plan->execute()
• line 385 of /backup/controller/restore_controller.class.php: call to restore_plan->execute()
• line 219 of /backup/util/ui/restore_ui.class.php: call to restore_controller->execute_plan()
• line 143 of /backup/restore.php: call to restore_ui->execute()

Any clues? I cant delete the activity submissions from students in this case. I tried to do as a test but looks like the array isnt getting the userid. So if i delete the assignment 55, when i tried to restore again the error goes to assignment 56 and so on.

Remembering that i already did the steps from this link:
https://docs.moodle.org/36/en/MySQL_full_unicode_support

And now my DB is:
Database engine: InnoDB
innodb_file_per_table: ON
innodb_file_format: Barracuda
In reply to Felipe Almeida de Souza

Re: "Error writing to database" when restoring course

by Felipe Almeida de Souza -
This error only ocurrs on my server, on the original server i can backup and restore this course without any error.
In reply to Felipe Almeida de Souza

Re: "Error writing to database" when restoring course

by Ken Task -
Picture of Particularly helpful Moodlers

Do you have access to the server from which these backups come?    Is there some sort of assignment plugin that doesn't exist on your server?

If you had access, you could inspect those assignments to see what's different about them, then might be able to adjust your server to be able to restore those courses.

If you don't have access, ask someone who does, to make a backup of that course and exclude those assignments ... naming the backup with a -na- in it's file name so you know there are 'no assignments'.

After restore, those assignments could be rebuilt ... new ... users of course, would not have submitted anything to those.

'SoS', Ken


In reply to Ken Task

Re: "Error writing to database" when restoring course

by Felipe Almeida de Souza -
I have limited access to the server. The assignment its a 6500 words essay (no file, just typing the text in the textbox).

If i restore the course without the assignments, i dont face any error. But if i try to restore just the assignment to the course later, i get the same error.

There is another way to rebuilt the assignments?

Thanks for the help