WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 13 months ago

#34189 new enhancement

Add warning about changing $table_prefix for existing database

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

Description

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 2 years ago.
Patch to include warning in wp-config.php
34189.patch (757 bytes) - added by stevenlinx 13 months ago.

Download all attachments as: .zip

Change History (10)

@bjerke-johannessen
2 years ago

Patch to include warning in wp-config.php

#1 @swissspidy
2 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
2 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.


15 months ago

#4 @jorbin
15 months ago

  • Keywords needs-patch added

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

#5 @Mista-Flo
14 months ago

In this part of codex ? https://codex.wordpress.org/Database_Description
This page is not really update btw.

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


14 months ago

#7 @morganestes
14 months ago

How about a notice on https://codex.wordpress.org/Editing_wp-config.php#table_prefix as the canonical reference, with a link from https://codex.wordpress.org/Database_Description (which is definitely in need of an update)?

@stevenlinx
13 months ago

#8 @stevenlinx
13 months 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.