Skip to:
Content
Pages
Categories
Search
Top
Bottom

Manually reset user id to higher number?


  • peterverkooijen
    Participant

    @peterverkooijen

    I get these error messages with my mailing list integration code?

    [04-Sep-2009 10:12:57] PHP Warning: join() [function.join]: Invalid arguments passed in /serverpath/wp-content/mu-plugins/bp-custom.php on line 363

    [04-Sep-2009 10:14:44] WordPress database error Duplicate entry ‘781’ for key 1 for query INSERT mailusers SET users_id=’781′, group_id=’1′, signup_date= UNIX_TIMESTAMP(), firstname= ‘Test’, lastname= ‘User’, email_address = ‘peter@emailaddress.net’ made by require, require_once, do_action, call_user_func_array, bp_core_do_catch_uri, load_template, require_once, custom_do_activation, wpmu_activate_signup, do_action, call_user_func_array, synchro_wp_usermeta

    The problem is that I tried to use the same ID from WPMU/BP in my mailing list, but my mailing list already has many more users on it.

    Is there a way to reset the members ID from now on to a higher value? Specifically, my latest member ID is 780, how can I make the next one to be 3000?

    What would happen if I sign up a test user and manually change his ID in the database to 3000? Would the next one take 3001? Or would I mess up the entire system?

    Or is there a cleaner, official way to do this?

Viewing 6 replies - 1 through 6 (of 6 total)
  • You can’t change the ID column in the wordpress users table as it’s an autoincrement field. MySQL might have some docs on the site if it’s possible to inflate it. Failing that, do a load of inserts / deletes and bump the number up ;)


    peterverkooijen
    Participant

    @peterverkooijen

    2000 insert/deletes. It’s gonna be a long night… ;-(

    Is inflate the technical term?

    Found this somewhere:

    If you just want to change the auto_increment without deleting everything, you can

    ALTER TABLE tbl_name AUTO_INCREMENT = xxx

    (where xxx is an integer). Or use the operations page in phpmyadmin …

    But what table(s?) should I apply that to? Only wp_users? Would the rest automatically follow?

    Scary stuff

    Apply it to whatever table you want to alter the auto_increment value for…


    peterverkooijen
    Participant

    @peterverkooijen

    That would be wp_users, but isn’t that ID used as a key (?) elsewhere in the database? Would it get “altered” automatically throughout the system?


    Jeff Sayre
    Participant

    @jeffsayre

    That would be wp_users, but isn’t that ID used as a key (?) elsewhere in the database? Would it get “altered” automatically throughout the system?

    No, in WPMU DBs, changing the auto increment field, or any other linked field, does not automatically propagate the changes throughout. The technical term for what you are referring to is referential integrity, with the specific subset of that called cascading changes.

    With the MySQL engine, cascading changes (update or delete) throughout the DB only can occur if the tables in the DB have been set up as type InnoDB and the appropriate foreign keys applied. WPMU’s tables are set up as type MyISAM. Before assuming that this was/is a bad choice, when it comes to MySQL, there are pros and cons with each table type. A conscious decision went into selecting MyISAM table types for WPMU’s DB.

    Now, with regards to the specific issue you are facing:

    Although all the tables in WPMU’s DB have an ID field that is set to auto_increment, the ID field in wp_users is used to assign a unique ID to each registered member of your site. That ID field ties into the other tables in the DB, where necessary, by mapping to an appropriate field–but not to the auto incremented ID field of the other tables.

    So, for example, the wp_user ID field forms a relationship in the wp_bp_friends table in two places–with the initiator_user_id and friend_user_id fields. Or as a specific example, wp_user ID field = 7 would form a relationship with the field in wp_bp_xprofile_data where the value of its user_id field equaled 7.

    You are on the verge of potentially causing a very big, possibly fatal problem for your MySQL DB. Before doing anything, back up your DB and be prepared for the very-real possibility that you are going to alter the table relationships (break them) to such a point that your DB will not function anymore. You will then have to delete all the data in the DB tables and then restore the data from your backup.

    You might even find yourself in the position of having to actually delete the entire DB and creating a new one from scratch. You’ will then need to restore from the back up. So you should also make sure you have a copy of the DB settings in WPMU’s wp-config.php file as you will have to recreate the new DB exactly to match the settings found in that configuration file.


    peterverkooijen
    Participant

    @peterverkooijen

    Thanks Jeff Sayre, that confirms what I feared.

    So is there any way to do this safely? Where can I get a complete list of all the tables and ID fields I would have to manually alter?

    Or is there a possible php hack? Set id=id+3000 somewhere at the point of creation?

    If I abandon the idea of having the same ID in my mailing list as WPMU/BP I could just do something like this I guess:

    INSERT mailusers SET users_id=INCREMENTAL ...

    Have to find the right word/syntax for that. Or could I leave it out altogether?

    EDIT: Just removing users_id= solves the problem. It doesn’t look like it’s worth the trouble to keep the IDs the same.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Manually reset user id to higher number?’ is closed to new replies.
Skip to toolbar