dbDelta does not create Table, but returns success

I wrote a Plugin, which creates a table on activation. On previous WP Versions, it worked fine.

Now it doesn’t.
This is my function:

function on_activation(){
            global $wpdb;
            $table_name = $wpdb->prefix."tc_competition_data_all_countries_and_fields";
            $sql = "CREATE TABLE $table_name (
              mail VARCHAR(55),
              id VARCHAR(255) NOT NULL,
              time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
              name VARCHAR(255) NOT NULL,
              stra VARCHAR(255) NOT NULL,
              ort VARCHAR(255) NOT NULL,
              uid VARCHAR(255) NOT NULL,
              msg VARCHAR(500) NOT NULL,
              meta1 VARCHAR(500) NOT NULL,
              meta2 VARCHAR(500) NOT NULL,
              UNIQUE KEY id (id)
            );";
            #dbDelta( $sql );
            $c  = dbDelta( $sql );
        }

It gets fied with this hook:

register_activation_hook( __FILE__, array( 'tc_comp_form', 'on_activation' ) );

When I do a vardump in for $c, it returns, that the table has been created, but it does not exists.

What could be the issue?

Many Thanks!

1 Answer
1

The Problem was in this line:

time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,

I changed it to:

time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

Now, it works.

Leave a Comment