Title: Create table on activation problem
Last modified: August 19, 2016

---

# Create table on activation problem

 *  [rgtyf](https://wordpress.org/support/users/rgtyf/)
 * (@rgtyf)
 * [17 years, 5 months ago](https://wordpress.org/support/topic/create-table-on-activation-problem/)
 * Hello to everyone,
 *  I want my plugin to create a table when it is activated. Could anyone, please,
   tell me what I am doing wrong here?
 * MY CODE:
 * function TagRank_Activate()
    { $tags_ratings = $wpdb->prefix . “tags_ratings”;
 *  if ($wpdb->get_var(“SHOW tables LIKE ‘$tags_ratings'”) != $tags_ratings)
    { 
   $sql = “CREATE table” . $tags_ratings . “( id mediumint(9) NOT NULL AUTO_INCREMENT,
   post_id mediumint(9) NOT NULL, tag_id mediumint(9) NOT NULL, rating bigint(11)
   DEFAULT ‘0’ NOT NULL, UNIQUE KEY id (id) );”; require_once(ABSPATH . ‘wp-admin/
   upgrade-functions.php’); dbDelta($sql); } }
 * add_action(‘activate_tagrank.php’, ‘TagRank_Activate’);
 * My plugin is stored at wp-content/plugins/tagrank.php.
 * Thank you very much.

Viewing 1 replies (of 1 total)

 *  [johnmorris09](https://wordpress.org/support/users/johnmorris09/)
 * (@johnmorris09)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/create-table-on-activation-problem/#post-951174)
 * I know it’s old here, but thought I would reply, since this is the number one
   listing for “create table problem” and I didn’t see the solution posted anywhere
   else.
 * This code doesn’t work, because you need backticks around your table name and
   table columns in your sql query. I can’t even post the correct code here, because
   the editor keeps stripping them out no matter what I do. I would guess that’s
   why the solution is so elusive… no one can get it to post. 🙂
 * Anyway, backticks are the little apostrophe-looking things all the way to the
   left hand side of your keyboard on the numbers row… so, it goes…
 * 3… 2… 1… backtick…
 * Not the squiggly one, which is a tilde… just the apostrophe-looking one. That’s
   it…
 * Put those around the quotations around tablename and around the column ids… i.
   e. id, post_id, etc… and you’ll be good to go.
 * I banged my head against the wall for a day trying to figure this out… it wasn’t
   till I stumbled onto an obscure video that the author mentioned this.
 * I’m not sure why it’s not mentioned in the codex, but it probably should be.
 * Thanks!!
    John

Viewing 1 replies (of 1 total)

The topic ‘Create table on activation problem’ is closed to new replies.

## Tags

 * [activate](https://wordpress.org/support/topic-tag/activate/)
 * [create table](https://wordpress.org/support/topic-tag/create-table/)

 * 1 reply
 * 2 participants
 * Last reply from: [johnmorris09](https://wordpress.org/support/users/johnmorris09/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/create-table-on-activation-problem/#post-951174)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
