Note: You are currently viewing documentation for Moodle 1.9. Up-to-date documentation for the latest stable version is available here: DuplicateUsernames.

DuplicateUsernames: Difference between revisions

From MoodleDocs
(Find and eliminate duplicate usernames)
 
No edit summary
Line 1: Line 1:
You may see an error message when you're upgrading to Moodle 1.8 if you have a duplicate username in your Moodle's user table. You can search for duplicate usernames in your user table with the following query:
You may see an error message when you're upgrading to Moodle 1.8 if you have a duplicate username in your Moodle's user table. You can search for duplicate usernames in your user table with the following query:


select username,
<pre>select username,
count(username) AS instances
count(username) AS instances
from PREFIX_user
from PREFIX_user
group by username
group by username
having (count(username) > 1);
having (count(username) > 1);</pre>


Note that you'll have to change PREFIX_user to whatever you call your user table, e.g. mdl_user.
Note that you'll have to change PREFIX_user to whatever you call your user table, e.g. mdl_user.
Line 12: Line 12:


When you're in the clear, you can create the index with the following query:
When you're in the clear, you can create the index with the following query:
CREATE UNIQUE INDEX user_mneuse_uix ON PREFIX_user (mnethostid, username);
<pre>CREATE UNIQUE INDEX user_mneuse_uix ON PREFIX_user (mnethostid, username);</pre>


If that succeeds, you're done!
If that succeeds, you're done!


If this fails, please file another bug report, because it's likely that something else is causing your problem.
If this fails, please file another bug report, because it's likely that something else is causing your problem.

Revision as of 05:36, 5 March 2007

You may see an error message when you're upgrading to Moodle 1.8 if you have a duplicate username in your Moodle's user table. You can search for duplicate usernames in your user table with the following query:

select username,
count(username) AS instances
from PREFIX_user
group by username
having (count(username) > 1);

Note that you'll have to change PREFIX_user to whatever you call your user table, e.g. mdl_user.

If this returns a list of usernames and instances, you've somehow got duplicate username entries in your database. With any luck, you'll be able to delete or rename one of these usernames, and then the database will be able to create the index on your table. The index creation will not succeed until the query above returns zero results.

When you're in the clear, you can create the index with the following query:

CREATE UNIQUE INDEX user_mneuse_uix ON PREFIX_user (mnethostid, username);

If that succeeds, you're done!

If this fails, please file another bug report, because it's likely that something else is causing your problem.