[wp-hackers] Recommended way to change column name?
wp at andrewnacin.com
Sun May 30 16:29:14 UTC 2010
On Sun, May 30, 2010 at 7:55 AM, Mike Walsh <mike_walsh at mindspring.com>wrote:
> I have a plugin which has its own tables. One of the tables I had created
> while back for some future functionality that I am just getting to
> implementing. In the course of working on it I decided that I didn't need
> several of the columns and more importantly, I wanted to change the name of
> the primary index column to be more descriptive than the generic "id" name
> gave it originally.
> I use dbDelta() to create my tables. So I changed the SQL to reflect the
> new updated table I wanted but the call to dbDelta() doesn't seem to have
> any affect other than adding columns. Doing some searching it appears
> dbDelta() has some limitations and I am wondering if changing column names
> is one of them. Because I have never used this table I suppose I could
> check for existence and drop it and let dbDelta() recreate it but I am
> wondering what the recommended way to make table changes is?
Correct, dbDelta does not drop or rename fields; it only can alter the
properties of them, along with indexes, etc. You would make SQL calls
manually during an upgrade routine to alter any fields. (This is also how
core does this.)
More information about the wp-hackers