S
S
Sergey Burduzha2018-05-28 20:55:37
MySQL
Sergey Burduzha, 2018-05-28 20:55:37

Why is the sql query not working?

I want to add a new field in the wp_posts table when activating the plugin in WordPress.

register_activation_hook( __FILE__, 'wfm_create_field' );
function wfm_create_field(){
    global $wpdb;

    $query = "ALTER TABLE $wpdb->posts ADD 'wfm_views' INT NOT NULL DEFAULT '0'";

    $wpdb->query($query);
}

Here is the request from phpmyadmin
ALTER TABLE `wp_posts` ADD `wfm_veiws` INT(100) NOT NULL DEFAULT '0' AFTER `comment_count`;

And it gives an error incorrect default value
Here is the data
5b0c5a88e99df570407403.jpeg
and here is the error
5b0c5a9bc7f82509380689.jpeg
How to solve?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Burduzha, 2018-05-28
@serii81

Issue resolved.
Changed the entry
Removed quotes from wfm_views.
The only question left is why this code in phpmyadmin does not work?
And I found a solution to this question
. It worked only after I set the default value for post_date post_date_gmt post_date_modified post_date_modified_gmt.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question