Opened 9 years ago
Closed 6 hours ago
#34189 closed enhancement (fixed)
Add warning about changing $table_prefix for existing database
Reported by: | bjerke-johannessen | Owned by: | jorbin |
---|---|---|---|
Milestone: | 6.7 | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | Bootstrap/Load | Keywords: | 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)
Change History (12)
#1
@
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
@
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
@
8 years 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
@
8 years 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.
8 years ago
#7
@
8 years 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)?
#8
@
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.
Patch to include warning in wp-config.php