We are running 1.7+ and lately it has been running frustratingly slow. Seeing that things couldn't get any worse I decided to upgrade to 1.8 beta - thinking that this might sort out any database problems. However the upgrade stalls and gives the following message
1062: Duplicate entry '1-kh8866' for key 3
adodb_mysql._execute(CREATE UNIQUE INDEX mdl_user_mneuse_uix ON mdl_user (mnethostid, username), false) % line 889, file: adodb.inc.php
adodb_mysql.execute(CREATE UNIQUE INDEX mdl_user_mneuse_uix ON mdl_user (mnethostid, username)) % line 89, file: dmllib.php
execute_sql(CREATE UNIQUE INDEX mdl_user_mneuse_uix ON mdl_user (mnethostid, username), true) % line 1899, file: dmllib.php
execute_sql_arr(Array, true, true) % line 1080, file: ddllib.php
add_index(Object:xmldbtable, Object:xmldbindex) % line 342, file: upgrade.php
ErrorScroll to next warning
Scroll to previous warning Main Upgrade failed! See lib/db/upgrade.php
Scroll to continue button
Is anyone able to advise me how to fix this problem? Is there a table that I could simply delete and reinstall without loosing user data. I don't know much about databases but am good at tinkering, I just need to know where to start.
select count(id) from mdl_user where username='kh8866';
The result should be an integer - if it's greater than 1, then that will explain your problem.
It looks like the database is trying to create an index on (mnethostid, username) and it's failing because the username 'kh8866' occurs twice in your database. It's difficult to see how this would be possible - usernames should be unique, after all - but that seems to be what is happening.
Thanks for responding, the result is 9, and when I checked on that name in the user table it was there 9 times! Just this year we have enroled our students with ldap, I know it is throwing up errors when I turn on debugging, maybe something is happening at that end.
I created a page on the docs site that covers this issue:
I also committed a change to the Moodle code that allows upgrades to continue if duplicate usernames exist in the user table, but I think that in the long run, duplicate usernames could cause some tricky bugs, and it is "strongly advised" ;) that you should resolve the duplicates in your DB.
The query I added to the docs will help you identify any other usernames that have been added to your DB more than once.
Sorry you've been having problems with your Moodle - I hope it's not too much hassle to fix.
I want to have a look at the LDAP code and see if there's anything strange in there which could be encouraging it to create duplicate user records.
Notice: Undefined variable: module in C:\XAMPP\xampp\htdocs\lib\moodlelib.php on line 5340
this is one that shows up all the time
these ones happen with the ldap users
Notice: Undefined index: office in C:\XAMPP\xampp\htdocs\auth\ldap\lib.php on line 129
Notice: Undefined index: office in C:\XAMPP\xampp\htdocs\auth\ldap\lib.php on line 138
Notice: Undefined index: desc in C:\XAMPP\xampp\htdocs\auth\ldap\lib.php on line 129
Notice: Undefined index: desc in C:\XAMPP\xampp\htdocs\auth\ldap\lib.php on line 138
Warning: Cannot modify header information - headers already sent by (output started at C:\XAMPP\xampp\htdocs\auth\ldap\lib.php:129) in C:\XAMPP\xampp\htdocs\lib\moodlelib.php on line 2125
I was getting a similar error with the following message when trying to restore Turnitin assignments to a course.
I think it was because we had changed all our email addresses to firstname.lastname@example.org and Turnitin relies on the email address to know who is who. So I changed the email address back and it restored with no error.
While the email address remained as email@example.com I got the following error:
Error writing to database
More information about this error
Debug info: Duplicate entry '1-rehkmle' for key 'mdl_user_mneuse_uix'
INSERT INTO mdl_user (city,auth,username,lang,confirmed,lastip,timecreated,timemodified,mnethostid,calendartype,maildisplay,mailformat,maildigest,autosubscribe,trackforums) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
0 => '',
1 => 'manual',
2 => 'rehkmle',
3 => 'en',
4 => 1,
5 => '126.96.36.199',
6 => 1443606504,
7 => 1443606504,
8 => '1',
9 => 'gregorian',
10 => '2',
11 => '1',
12 => '0',
13 => '1',
14 => '0',
Error code: dmlwriteexception
line 446 of /lib/dml/moodle_database.php: dml_write_exception thrown
line 1164 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
line 1210 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
line 96 of /user/lib.php: call to mysqli_native_moodle_database->insert_record()
line 4093 of /lib/moodlelib.php: call to user_create_user()
line 94 of /mod/turnitintool/backup/moodle2/restore_turnitintool_stepslib.php: call to create_user_record()
line 137 of /backup/util/plan/restore_structure_step.class.php: call to restore_turnitintool_activity_structure_step->process_turnitintool_courses()
line 103 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 91 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 195 of /backup/moodle2/restore_activity_task.class.php: call to base_task->execute()
line 177 of /backup/util/plan/base_plan.class.php: call to restore_activity_task->execute()
line 167 of /backup/util/plan/restore_plan.class.php: call to base_plan->execute()
line 333 of /backup/controller/restore_controller.class.php: call to restore_plan->execute()
line 184 of /backup/util/ui/restore_ui.class.php: call to restore_controller->execute_plan()
line 111 of /backup/restore.php: call to restore_ui->execute()