Restore Images on your Digital Camera Card

Uh oh - you just took a bucketful of honeymoon photos and towards the end of the trip your friend borrows the camera and accidentally formats the memory card.  Ahhhhh!!!  Don't freak out yet. Check out Disk Doctor and get $5 off as a CWD visitor. It just may save the day.

Free Logo Creator

Logo creation is a long, drawn-out creative process that can cost millions. But a good logo doesn't have to cost a fortune, and you don't even need to hire a professional design team. Check out Logo Creator (Win | Mac) to get started, read our article on obtaining your own Free Logo Creator.



Sep 14 2007

Drupal - How to Change Your User ID


Filed under: Content Management Systems » Drupal,
Tools:

How to change your user ID (without jacking everything up)

We're going to show you how to update your Drupal user ID without wreaking havoc across your site.  If you are comfortable administering your database tables updating a user ID for a particular user is not all that difficult.  The key is updating all the tables where the variable for user ID, "uid", takes place.  At the time of this writing we were not aware of a Drupal module that automates this process.  If you know of one, or are interested in working on one, please post below.

Why would you want to change a user ID?

The reason we initially came across the need to change a user ID is due to the fact that we were in the process of embedding a forum installation (phpBB) within Drupal (read our article on integrating phpBB with Drupal for the details).  phpBB, for some odd reason, required the use of Drupal user ID #2 as the primary administrator.  We therefore had to regain control (and therefore change), user ID #2. 

Which tables do I need to update?

You'll need to update the following tables (using, for example, phpMyAdmin), in order to cover the most common instances of "uid" (if you are using additional contrib modules you'll want to search for additional tables making use of "uid).  Important: Before proceeding, as with any database updates, make sure you backup your database in case something goes awry!  Once you're ready, execute the following SQL command on the tables below (in this example we're changing user ID 5 to user ID 2).  Note:  You need to make sure you're updating to a user ID that does not already exist!  If the user ID you wish to update to already exists, simply take control of that user and create a new user for the former user.  If it does not exist, proceed with the following:
UPDATE node SET uid = 2 WHERE uid = 5;
You'll want to update the tables:

  • users
  • user_roles
  • update node
  • node_revisions
  • comments
  • subscriptions

Voila :)  If you updated all instances of uid 2 you should see all nodes intact on your site.  If you forgot some, you may see instances of "n/a" in place of posts, or modules behaving oddly.  If this is the case, restore your backup and find the additional tables utilizing "uid" that need updating via the above SQL command.

Average: 5 (1 vote)
Select your preferred way to display the comments and click "Save settings" to activate your changes.

Hi

Nice information provided here which is very useful to everyone...I am not a huge fan of this side, there do seem to be a lot these days...thanks for posting...Let me know more about this one... Elenora

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Textual smileys will be replaced with graphical ones.

More information about formatting options

CAPTCHA
This question is used to make sure you are a human visitor and to prevent spam submissions.