Make WordPress Core

Opened 9 years ago

Last modified 5 years ago

#34189 new enhancement

Add warning about changing $table_prefix for existing database

Reported by: bjerke-johannessen's profile bjerke-johannessen Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.4
Component: Bootstrap/Load Keywords: needs-codex has-patch
Focuses: docs Cc:


When changing the $table_prefix for an existing database, it is not sufficient to rename the tables. You also have to change several values in at least two tables. In my case, changing prefix from "wp_" to "bbj_wp_" this involved at least the following SQL:

UPDATE bbj_wp_options
SET option_name = 'bbj_wp_user_roles'
WHERE option_name = 'wp_user_roles';

UPDATE bbj_wp_usermeta
SET meta_key = 'bbj_wp_user_level'
WHERE meta_key = 'wp_user_level';

UPDATE bbj_wp_usermeta
SET meta_key = 'bbj_wp_capabilities'
WHERE meta_key = 'wp_capabilities';

The attached patch adds a warning to the generated wp-config.php file about this. There is much room for improvement here, including giving detailed information on what needs to be changed or even re-writingthe particular misfeature that stores tables names in other tables. The patch is intended as a stop-gap 'til such improvements are made. Hopefully this will prevent others from chasing down the same wildly unexpected behavior should they decide to change $table_prefix

Attachments (2)

wordpress.patch2 (616 bytes) - added by bjerke-johannessen 9 years ago.
Patch to include warning in wp-config.php
34189.patch (757 bytes) - added by stevenlinx 8 years ago.

Download all attachments as: .zip

Change History (10)

9 years ago

Patch to include warning in wp-config.php

#1 @swissspidy
9 years ago

  • Component changed from Database to Bootstrap/Load
  • Focuses docs added

That sounds harsh, especially when it's all uppercase.

I'd rather say something like "Be careful when changing this afterwards".

#2 @SergeyBiryukov
9 years ago

  • Keywords needs-codex added

"...several rows in several tables" is vague, and wp-config.php doesn't seem like a right place for full instructions.

This should probably be explained somewhere in Codex, and then we could link there.

This ticket was mentioned in Slack in #core by jorbin. View the logs.

8 years ago

#4 @jorbin
8 years ago

  • Keywords needs-patch added

I agree with @SergeyBiryukov on this. The documentation should live on and the language in wp-config should be friendlier and supportive.

#5 @Mista-Flo
8 years ago

In this part of codex ?
This page is not really update btw.

This ticket was mentioned in Slack in #docs by morganestes. View the logs.

8 years ago

#7 @morganestes
8 years ago

How about a notice on as the canonical reference, with a link from (which is definitely in need of an update)?

8 years ago

#8 @stevenlinx
8 years ago

  • Keywords has-patch added; needs-patch removed

i) I've revised the patch with better wording as suggested by @jorbin. Also, with proper formatting.

ii) For full documentation on changing the DB table_prefix, I agree with @morganestes in updating the Codex page Editing_wp-config.php#table_prefix.

However, in addition to linking the Database Description Codex page, I think most people are better off using a plugin such as Change DB Prefix than doing it manually. So, in the documentation, we may want to make a mention of this.

Note: See TracTickets for help on using tickets.