WordPress.org

Ready to get started?Download WordPress

Forums

dbDelta upgrade problem (2 posts)

  1. Ajay
    Member
    Posted 5 years ago #

    I'm following the tutorial at http://codex.wordpress.org/Creating_Tables_with_Plugins to create and then modify a table for my plugin.

    I was able to create the tables successfully. Now, I have the need to add an extra column to one of the tables.

    I'm using this code:

    // Upgrade table code
       $installed_ver = get_option( "tptn_db_version" );
    
       if( $installed_ver != $tptn_db_version ) {
    
    	$sql = "CREATE TABLE " . $table_name . " (
    		accessedid int NOT NULL AUTO_INCREMENT,
    		postnumber int NOT NULL,
    		cntaccess int NOT NULL,
    		PRIMARY KEY  (accessedid)
    	);";
    
          require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
          dbDelta($sql);
    
    	$sql = "CREATE TABLE " . $table_name_daily . " (
    		accessedid int NOT NULL AUTO_INCREMENT,
    		postnumber int NOT NULL,
    		cntaccess int NOT NULL,
    		dp_date date NOT NULL default CURDATE(),
    		PRIMARY KEY  (accessedid)
    	);";
    
          require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
          dbDelta($sql);
    
          update_option( "tptn_db_version", $tptn_db_version );
      }

    The extra column to add is the dp_date to $table_name_daily.

    However, this hasn't changed the database structure at all.

    In the past, when I needed to create the second table, the upgrade worked. However, it isn't altering the tables.

    Any suggestions, workarounds?

  2. Ajay
    Member
    Posted 5 years ago #

    I was able to fix this by removing default CURDATE()

Topic Closed

This topic has been closed to new replies.

About this Topic