Title: Adding Table on Plugin Activation / dbDelta
Last modified: August 20, 2016

---

# Adding Table on Plugin Activation / dbDelta

 *  [emailmike1994](https://wordpress.org/support/users/emailmike1994/)
 * (@emailmike1994)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/adding-table-on-plugin-activation-dbdelta/)
 * I really could use some help. I’m starting to lose my mind.
 * I wrote a plugin a ways back, which worked in the past. On install / activation
   it is supposed to create a table in the database. I’ve installed the plugin on
   a new site and I cannot for the life of me get it to create a table like it had
   before.
 * I replaced my code with the sample code from the Codex and it works. I just can’t
   see how mine differs.
 * I’ve tried to replace what’s in the sample code with my own fields and data types
   and I’m back to square one. The plugin won’t write the table.
 * I know plenty of people have had issues because of dbDelta and how particular
   it is about formatting. I’ve tried to follow people’s advice for making mine 
   conform to those rules, but to no avail.
 * Please help me see where I’m going wrong.
 *     ```
       global $abc_reviews_db_version;
       $abc_reviews_db_version = "1.0";
   
       function abc_reviews_install() {
          global $wpdb;
          global $abc_reviews_db_version;
   
          $table_name = $wpdb->prefix . "abc_reviews";
   
       $sql = "CREATE TABLE " . $table_name . " (
                 id mediumint(9) NOT NULL AUTO_INCREMENT,
                 review_date DATE(50) NOT NULL,
                 review_author VARCHAR(250) NOT NULL,
                 text text NOT NULL,
                 UNIQUE KEY id (id)
               );";
   
       require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
       dbDelta($sql);
   
         add_option("abc_reviews_db_version", $abc_reviews_db_version);
       }
   
       register_activation_hook(__FILE__,'abc_reviews_install');
       ```
   

The topic ‘Adding Table on Plugin Activation / dbDelta’ is closed to new replies.

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [dbDelta()](https://wordpress.org/support/topic-tag/dbdelta/)
 * [tables](https://wordpress.org/support/topic-tag/tables/)

 * 0 replies
 * 1 participant
 * Last reply from: [emailmike1994](https://wordpress.org/support/users/emailmike1994/)
 * Last activity: [13 years, 4 months ago](https://wordpress.org/support/topic/adding-table-on-plugin-activation-dbdelta/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
