Your Moodle version

Admin tools: Merge user accounts

Maintained by Picture of Nicolas Dunand Nicolas Dunand, Picture of Jordi Pujol-Ahulló Jordi Pujol-Ahulló
This administration tool will merge two Moodle user accounts into one.
Moodle 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8

The intent is to assign all activity & records from user A to user B. This will give the effect of user B seeming to have done everything both users have ever done in Moodle.

This tool replaces the old report_mergeusers, which is now obsolete.


Screenshot #0
Screenshot #1
Screenshot #2


Picture of Nicolas Dunand
Nicolas Dunand (Lead maintainer): author
Picture of Jordi Pujol-Ahulló
Jordi Pujol-Ahulló: author
Picture of Forrest Gaston
Forrest Gaston: contributor
Mike Holzer
Mike Holzer: contributor
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Picture of Mono Lith
    Fri, Nov 6, 2015, 6:29 PM

    This is a very useful tool.

    Looking forward for 2.9 compatibility results!


  • Picture of Anna Krassa
    Wed, Nov 25, 2015, 4:30 PM
    Hello Nicolas and Jordi,

    Thank you very much for this great tool! We use it a lot in our site.

    +1 for Arto's suggestion on setting up the capabilities. I also want to give merging rights to Managers. Of course I share Jordi's worries about safety, but imagine how risky it would be if instead of allowing Managers merge users, we have to change the Manager's role into Admin!

    Plus, I don't know if this is the "default" attribute, but in our site, whenever we merge two users, the account to be removed is not deleted but suspended. Which is also a very good "just in case" solution...

    I have already said in GitHub, that I am not a developer but I am very interested in this feature and I 'll be glad to assist if I can.

    Best wishes,
  • Picture of Anna Krassa
    Fri, Jan 8, 2016, 4:11 PM
    Hello everyone,

    I am using User Merge in Moodle 3.0 now and I confirm that everything works nicely.

    There is one case though that gives me the following error, but I was receiving the same error in Moodle 2.8.


    Some error occurred:

    Exception thrown when merging: 'Error writing to database".

    #0 /home/learn/public_html/lib/dml/pgsql_native_moodle_database.php(244): moodle_database->query_end(false)
    #1 /home/learn/public_html/lib/dml/pgsql_native_moodle_database.php(682): pgsql_native_moodle_database->query_end(false)
    #2 /home/learn/public_html/admin/tool/mergeusers/lib/table/generictablemerger.php(225): pgsql_native_moodle_database->execute('UPDATE mdl_cour...')
    #3 /home/learn/public_html/admin/tool/mergeusers/lib/table/generictablemerger.php(80): GenericTableMerger->updateRecords(Array, Array, 'userid', Array, Array)
    #4 /home/learn/public_html/admin/tool/mergeusers/lib/mergeusertool.php(281): GenericTableMerger->merge(Array, Array, Array)
    #5 /home/learn/public_html/admin/tool/mergeusers/lib/mergeusertool.php(216): MergeUserTool->_merge('6783', '6412')
    #6 /home/learn/public_html/admin/tool/mergeusers/index.php(135): MergeUserTool->merge('6783', '6412')
    #7 {main}

    Merge failed!
    Your database engine supports transactions. Therefore, the whole current transaction has been rolled back and no modification has been made to your database.


    Unfortunately the debugging option didn't gave us any direction on what to fix on database, could you please advice?

    Thank you in advance,
  • Picture of Jordi Pujol-Ahulló
    Fri, Jan 8, 2016, 6:31 PM
    Hi Kan!

    Thank you very much for reporting.

    Please, report the line between your "Exception thrown...." and "Trace:", because there appears the key message for solving your conflict. It is an error on an UPDATE, so there would be something about compound keys that an UPDATE produces duplicate keys.

    Keep in touch,


  • Picture of Betsy Springer
    Sun, Jan 24, 2016, 5:32 AM
    do you know if this can be used if we use joomdle authentication?
  • Picture of Jordi Pujol-Ahulló
    Mon, Jan 25, 2016, 3:17 PM

    I suppose that joomdle authentication is just another kind of authentication plugin, and so, it will appear in the column user.auth with the corresponding value. Therefore, beforehand, and having no prior experience on that, I suppose it will work straight away, as in other Moodle instance. The only think you have to take care of, is running it in some test environment and check that the auth type remains the corresponding for joomdle after merging.

    Always make some test NOT IN PRODUCTION environment, in this kind of scenarios. First test it, and then you could deploy it into production, as you would do with any other kind of plugin.

    It will be nice if you come back with the results.

    Thank you for contacting us!

  • Picture of Adrian Sutantio
    Wed, Feb 3, 2016, 1:30 PM
    Hi there,

    Thank you for the amazing plugin. We have used this several times when we were on Moodle 2.7. We have just upgraded our Moodle to 2.9 and I got this error when tried to use the plugin

    Exception thrown when merging: 'Error reading from database".
    Unknown column 'id' in 'field list'
    #0 /home/ddd/public_html/lib/dml/mysqli_native_moodle_database.php(1080): moodle_database->query_end(false)
    #1 /home/ddd/public_html/admin/tool/mergeusers/lib/table/generictablemerger.php(65): mysqli_native_moodle_database->get_records_sql('SELECT id FROM ...')
    #2 /home/ddd/public_html/admin/tool/mergeusers/lib/mergeusertool.php(281): GenericTableMerger->merge(Array, Array, Array)
    #3 /home/ddd/public_html/admin/tool/mergeusers/lib/mergeusertool.php(216): MergeUserTool->_merge('1709', '14610')
    #4 /home/ddd/public_html/admin/tool/mergeusers/index.php(135): MergeUserTool->merge('1709', '14610')
    #5 {main}

    Can you help please?
  • Picture of Jordi Pujol-Ahulló
    Wed, Feb 3, 2016, 3:33 PM
    Hi Adrian,

    I've just created

    This afternoon I'll be back to you.

  • Picture of Jordi Pujol-Ahulló
    Wed, Feb 3, 2016, 3:36 PM
    Hi all!

    We are happy to see that our plugin is one of the 2015 favourite Moodle plugins!!

    Follow the post on:

    Thanks Gavin, thanks Moodle, thanks Community, for this honour!!
  • Picture of Jordi Pujol-Ahulló
    Wed, Feb 3, 2016, 3:57 PM
    Hi again Adrian,

    Taking a closer look at your message, I need more details on what is the problem about, mainly the database table where the "id" column does not exist. Have you any custom plugin/development/?? which is using a table without an "id" column?

    It is very strange, since Moodle defines (via XMLDB editor) always an "id" column. Can you search for tables without "id" column?

    You can use this select to get the list of them:

    select distinct c.table_name from Information_schema.columns c left join (select table_name from information_schema.columns where column_name like 'id') t ON t.table_name = c.table_name WHERE t.table_name IS Null and c.table_name like 'mdl_%';

    replace "mdl_" for your own table prefix.

    Thanks in advance!
  • Picture of Chris Chapman
    Wed, Mar 2, 2016, 10:17 PM
    Hi all ,

    Thanks for this plugin is a true life-saver! been using it with 2.6 and 2.9 since August 2015, no hitches till now. I have a user to merge but throwing this error Exception thrown when merging: 'Error writing to database".
    Duplicate entry '11079-13879-0-0' for key 'mdl_assisubm_assusegroatt_uix'

    But I cant find the offending entry in any of the tables other than tool_mergeusers to change it...

    Any suggestions?
  • Picture of Chris Chapman
    Wed, Mar 2, 2016, 11:33 PM
    Managed to rectify the issue - removed all records in for the User 13879 in assign_submissions. worked fine then, User must have submitted the same assignment in both accounts...
  • Picture of C Behan
    Mon, Apr 18, 2016, 6:59 PM
    Hi Nicholas, Jordi,

    Thank you for this excellent plugin. I'm wondering if you're planning to upgrade it for Moodle 3.0?

    Thanks, Catherine
  • Picture of Jordi Pujol-Ahulló
    Mon, Apr 18, 2016, 7:11 PM

    Thanks for asking and for your interest!

    Actually, the source code is already updated to work on Moodle 3 (see in the branch "master"). We only need to update this site to reference to the last code version.

    Thanks for pointing it out!


  • Picture of C Behan
    Wed, Apr 20, 2016, 12:06 AM
    Thanks Jordi smile
1 2 3 4 5
Please login to post comments