• Resolved dutt3684

    (@dutt3684)


    [11-Mar-2024 03:09:26 UTC] WordPress database error Table ‘wp_ts_redirects’ already exists for query RENAME TABLE ts_redirects TO wp_ts_redirects made by require(‘wp-blog-header.php’), wp, WP->main, do_action_ref_array(‘wp’), WP_Hook->do_action, WP_Hook->apply_filters, ts_redirects::redirects_301_do_redirect, Redirects->getAll, Redirects->checkForRedirectsTable This error shown on database while activating plug in — kindly let us know, what to do

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Alexandru Tapuleasa

    (@talextech)

    Hi,

    There are a few lines of code that were meant to add the wp_ prefix to the redirects table as a while back the plugin didn’t add that.

    In your case it seems like you ended up both with the unprefixed table and the prefixed table at the same time for some reason 🙁

    You will need to delete the ts_redirects table from the database manually and leave just wp_ts_redirects

    Thread Starter dutt3684

    (@dutt3684)

    Hi, Thanks for your response. I have trying finding table and find “ts-redirects.js” in JS folder and no other file found here with naming “wp_ts_redirects” file at any of file or folder, Kindly advise what to do . Below is the coding I found related to details given by you, Kindly make a look is this the fil you are writing about:–

    <?php
    class Redirects
    {
    function delete()
    {
    global $wpdb;

    $sql = "TRUNCATE TABLE {$wpdb->prefix}ts_redirects";
    $wpdb->query($sql);

    } // delete

    function edit($title, $section, $new_link, $old_link)
    {
    global $wpdb;
    $sql = $wpdb->prepare(“INSERT INTO {$wpdb->prefix}ts_redirects (title, section, new_link, old_link) VALUES (%s, %s, %s, %s)”, array($title, $section, $new_link, $old_link));
    $wpdb->query($sql);
    } // edit

    function getFields($id)
    {
    global $wpdb;

    $sql = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}ts_redirects WHERE id = %d", array($id));
    $result = $wpdb->query($sql);
    if ($result !== 0) {
      $fields = array();
      foreach ($wpdb->get_results($sql) as $row) {
        $fields['title'] = $row->title;
        $fields['section'] = $row->section;
        $fields['new_link'] = $row->new_link;
        $fields['old_link'] = $row->old_link;
      }
    
      return $fields;
    } else {
      return false;
    }

    } // getFields

    function createRedirectsTable()
    {
    global $wpdb;

    $sql = "CREATE TABLE {$wpdb->prefix}ts_redirects (id BIGINT(20) PRIMARY KEY AUTO_INCREMENT,title TEXT,section TEXT, new_link TEXT, old_link TEXT)";
    $wpdb->query($sql);

    } // createRedirectsTable

    function checkForRedirectsTable()
    {
    global $wpdb;

    $sql = "SHOW TABLES LIKE 'ts_redirects'";
    $result = $wpdb->get_results($sql);
    if (sizeof($result) == 1) {
      $wpdb->query("RENAME TABLE ts_redirects TO {$wpdb->prefix}ts_redirects");
    }
    
    $sql = "SHOW TABLES LIKE '{$wpdb->prefix}ts_redirects'";
    $result = $wpdb->get_results($sql);
    if (sizeof($result) != 1) {
      $this->createRedirectsTable();
    }

    } // checkForRedirectsTable

    function getAll()
    {
    global $wpdb;

    $this->checkForRedirectsTable();
    
    $sql = "SELECT * FROM {$wpdb->prefix}ts_redirects ORDER by id ASC";
    $result = $wpdb->query($sql);
    if ($result !== 0) {
    
      $id_arr = array();
      foreach ($wpdb->get_results($sql) as $row) {
        $id_arr[] = $row->id;
      }
    
      return $id_arr;
    } else {
      return false;
    }

    } // getAll

    function remove($custom_id)
    {
    global $wpdb;

    $sql = $wpdb->prepare("DELETE FROM {$wpdb->prefix}ts_redirects WHERE id = %d", array($custom_id));
    $wpdb->query($sql);

    }
    } // remove

    $redirectsplugin = new Redirects();
    $GLOBALS[‘redirectsplugins’] = $redirectsplugin;

    • This reply was modified 2 years, 2 months ago by dutt3684.
    • This reply was modified 2 years, 2 months ago by dutt3684.
    • This reply was modified 2 years, 2 months ago by dutt3684.
    Thread Starter dutt3684

    (@dutt3684)

    kindly reply on this

    Plugin Author Alexandru Tapuleasa

    (@talextech)

    I thought I did, sorry. Like my first reply says “you will need to delete the ts_redirects table from the database“.

    It’s not a file, you need to access your database via phpMyAdmin or whatever tool your host provides you with and delete it from there. Not the wp_ts_redirects table, just ts_redirects (without the wp_ prefix)

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘error on error log while activating plug in’ is closed to new replies.