I’ve never had any luck with dbdelta, it has worked spottily at best, and when I code, that’s just not good enough. My method for handling DB changes is to use database versions. So when I create a plugin, I also set the database version, then if I want to update the database, I do a check against the current dbversion (almost always stored in the wp_options table), if it’s less than the new DB version, I’ll run a series of updates. I’ll repeat the process if I release another update that requires database structure changes. This allows users to update the plugin, even from a very old version, and still be assured that the database format will be correct. This method also holds up if the data needs to be transformed and re-entered into the database, as it will update through every structural change as though the plugin were being updated incrementally.
Related Posts:
- Version upgrade: can my plugin filter the SQL statements issued during a database upgrade?
- dbDelta() Error – Incorrect index name ” for query ALTER TABLE
- How to update an existing table while updating plugin?
- dbDelta not installing database
- How can I get a plugin to hook ‘dbdelta_queries’ — a filter used during version update?
- Post meta vs separate database tables
- WordPress Update Plugin Hook/Action? Since 3.9
- Update Option Stored in Multi-Dimensional Array
- dbDelta not creating tables
- Default table collation on plugin activation?
- Writing a plugin that notify my friends of new post that mentions(@) them
- Getting wrong relationship value in $args in wp_Query?
- Not sure the best way to save custom plugin data
- The ideal place for storing persistent PHP objects
- Update exisiting site to 3.5 release candidate
- What is the correct way for plugins to create tables with special charset/collation considerations?
- dbDelta ALTER TABLE syntax?
- What is the added “complexity” of custom tables?
- Plugin development with unit tests
- How is the data stored in the database?
- Formatting of curly brackets array from WP database to get more readable output
- How to modify post content before writing to database?
- Actions or filters fired when data is saved in a custom table
- Hello dolly type plugin that allows people to add their own
- Sample — test — data for large WordPress install
- Custom Plugin Database relations
- Database for development
- Is there a naming convention for database tables created by a plugin?
- Activation hook not creating table
- Is the usage of ON DELETE CASCADE wrong or not allowed on wordpress?
- Saving data from block editor to the database
- What for the tables ending with the meta used in database of wordpress?
- Get a custom table to an array
- Plugin Upgrade Strategy
- How to Create database table when Plugin installed/activated, and delete database when Plugin deleted
- Can a plugin be used to contain all custom functions to extend other plugins
- How a deprecated function can crash WordPress site while upgrading
- Subscribe to author?
- I’m designing a plugin to create database indexes. Suggestions?
- WordPress database error for query INSERT INTO
- How to connect to AWS RDS external database (not for the core WordPress db)
- Upgrade private plugin without deleting files?
- How should I store a log for my plugin
- How to create database table, add data, update and delete using wpdb via plugins?
- dbDelta using Foreign key not working on update [duplicate]
- Using WPDB to output raw XML fails because of wp-blog-header.php
- Are there any scripts, classes, and/or functions built-in to WP for a plugin to export/import its saved data from wp_options?
- How to perform a heavy and long process in cron jobs?
- Is using custom table to suit business needs instead of transients a big hit to page load speed?
- Plugin Development for registered users
- Plugin development: delete options when updating to a new version
- Optimising a big WordPress site
- wpdb->prepare and mysql UPDATE – how is it done?
- dbDelta SQL Query Not Working
- Is it necessary to do validation again when retrieving data from database?
- What is the best way to store a few fields?
- Plugin: database creation
- Adding columns to core tables
- How to query custom db table?
- Delete data from database using row action
- Show dynamic list of products from custom api of another database under same host
- How do I have now a duplicated user entry if this is not allowed (and I cannot replicate it)?
- Alternative functions for mysql_free_result and mysql_ping in wordpress functions
- How best to handle database version dependence (from $wp_db_version)
- WP: Search and replace in DB programmatically
- Using AND and bracket grouping in SQL not working
- Two different wordpress sites – same server and IP address. Gaining Access to database 1 of 2
- WP Plugin with Upgrade option
- What might be the reason of Couldn’t fetch mysqli_result on another domain?
- Save temporary registration data
- Update plugin settings option_name for big plugin update
- $wpdb->update Issue
- WordPress database error: [Query was empty] – using $wpdb->prepare()
- Rewrite not working since upgrade to 5.9
- Error code when migrate
- Why User_login key doesn’t work with wp_update_user()
- How to store sensitive user data (passwords)
- How to get inserted row IDs for bulk/batch insert with wpdb query?
- WordPress Fatal error: Uncaught Error: Call to undefined function dbDelta()
- Use admin-post to submit form data to external database
- Save in my custom admin page and redirect to the saved object
- WordPress doesn’t create table on plugin activation
- Insert Data into Database
- Update database record in plugin
- How to store in the database directly the translation?
- How and when would I implement some code which would take data from one part of the Db and put it in another?
- pull data from wordpress database
- Ajax not working to insert, query and result data
- How to filter get_adjacent_post()?
- Associating special meaning with user id 0
- What method should I use to store my plugin data (multi level menus with options on each item)
- How to add additional field in a table row after creating a table?
- WordPress plugin tables become corrupt
- Post data in wp-admin to external database
- dbDelta not doing what it says
- How to create a database table in WordPress using PHP
- Leveraging Core Functionality in Icon Upload Plugin [closed]
- WordPress database error: [Table ‘bitnami_wordpress.questions’ doesn’t exist]
- Making a user platform reachable by a qr code on a pin-back-button [closed]
- multiple record insert creating many duplicate records