Count views without get_post_meta

If you provided full code, issue is probably in this line:

$wpdb->prepare("INSERT INTO 'myprefix_posts_views' (postid, ip, device) VALUES (%d, %s, %s) ON DUPLICATE KEY UPDATE create_at=VALUES(create_at)", $postID, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT']);

Because into column postid you are trying to put variable $postID, when you didn’t declare it anywhere. This column is NOT NULL, so probably you have database error while adding new row.

You can add this to confirm:

$test = $wpdb->query($post_view_sql);
var_dump( $test );

Replacing $postId with $post->ID should fix the issue.

error code: 523