• The plugin and install was working, then I added some fields to the data base table creation. Now it will not create the table. ( I deleted the old one in phpMyAdmin)

    The only code that was changed was in the $sql declaration. I keep looking at it and can not find what I did wrong.

    // First add a table to the WP db.
    global $equipment_db_version;
    $equipment_db_version = "1.0";
    
    function equipment_inventory_install() {
       global $wpdb;
       global $equipment_db_version;
    
       $table_name = $wpdb->prefix . "equipment_inventory";
    
       $sql = "CREATE TABLE $table_name (
       id mediumint (9) NOT NULL AUTO_INCREMENT,
       item_id VARCHAR (30) DEFAULT '' NOT NULL,
       image_path VARCHAR (100) DEFAULT '' NOT NULL,
       description VARCHAR (500) DEFAULT '' NOT NULL,
       location VARCHAR (100) DEFAULT '' NOT NULL,
       mfg VARCHAR (100) DEFAULT '' NOT NULL,
       model VARCHAR (100) DEFAULT '' NOT NULL,
       condition VARCHAR (500) DEFAULT '' NOT NULL,
       in_service date DEFAULT '0000-00-00' NOT NULL,
       out_of_service VARCHAR (30) DEFAULT '' NOT NULL,
       price VARCHAR (10) DEFAULT '' NOT NULL,
       modified datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
       modified_by VARCHAR (30)DEFAULT '' NOT NULL,
       UNIQUE KEY id (id)
       );";
    
    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    dbDelta( $sql );
    
       add_option( "equipment_inventory_db_version", $equipment_db_version );
    }
    register_activation_hook( __FILE__, 'equipment_inventory_install' ); // if the plugin is being activated create the db
    //
    // -- END -- table creation
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Mark_02660

    (@mark_02660)

    I just added each column one by one and the one that is not working is

    condition VARCHAR (500) DEFAULT '' NOT NULL,

    Any suggestions?

    Thread Starter Mark_02660

    (@mark_02660)

    More Info….

    I renamed “condition” to “con” and it works fine. So why will condition not work?

    Will not work -> condition VARCHAR (500) DEFAULT '' NOT NULL,
    Will work -> con VARCHAR (500) DEFAULT '' NOT NULL,

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Having problem with dbDelta()’ is closed to new replies.