1

I am working on a plugin development in WordPress and just created a table with code

global $wpdb;
    $createSQL = "
        CREATE TABLE `". $wpdb->prefix ."recipe_ratings` (
          `id` bigint(20) NOT NULL,
          `recipe_id` bigint(20) NOT NULL,
          `rating` float NOT NULL,
          `user_ip` varchar(32) NOT NULL
        ) ENGINE=InnoDB ". $wpdb->get_charset_collate() .";
        ";

    require( ABSPATH . '/wp-admin/includes/upgrade.php' ); // to include dbDelta fn which allows us to modify the wp database
    dbDelta( $createSQL );

But the table created does not show the edit, copy and delete options like the other tables. May be I need to enable something in the phpmyadmin interface but I am not sure what to do here.

No Edit, copy, delete option:

enter image description here

Expected Edit, Copy, Delete option

enter image description here

Kiran Dash
  • 4,816
  • 12
  • 53
  • 84

2 Answers2

3

Yes auto increment field not required. Only need to mention primary key.

$createSQL = "
        CREATE TABLE `". $wpdb->prefix ."recipe_ratings` (
          `id` bigint(20) NOT NULL,
          `recipe_id` bigint(20) NOT NULL,
          `rating` float NOT NULL,
          `user_ip` varchar(32) NOT NULL,
          PRIMARY KEY  (id)
        ) ENGINE=InnoDB ". $wpdb->get_charset_collate() .";
        ";

    require( ABSPATH . 'wp-admin/includes/upgrade.php' ); // to 
    include dbDelta fn which allows us to modify the wp database
    dbDelta( $createSQL );

Just mention "id" as a primary key. And no need to put forward slash ("/") before including "upgrade.php" file. Because "ABSPATH" returning the value with forward slash.

Sourav
  • 282
  • 1
  • 7
0

You have not added auto_increment on any field.Make one column as a primary key and auto_increment.

Gaurav
  • 442
  • 3
  • 7
  • Thanks. I followed your instruction and added one of the column as primary key. And it worked. Auto increment option was not needed. – Kiran Dash Sep 18 '17 at 04:44