Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6087379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:51:50+00:00 2026-05-23T11:51:50+00:00

Here’s an error that I’m having trouble with. It occurs when I use the

  • 0

Here’s an error that I’m having trouble with. It occurs when I use the dbDelta function in WordPress. I can’t really figure it out, perhaps someone else has experience something similar? My code:

$sql1 = "CREATE TABLE `".$table_name1."` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT  PRIMARY KEY ,
`blogid` INT( 11 ) NOT NULL ,
`symbol` VARCHAR( 255 ) NOT NULL
) ENGINE = MYISAM";

I trigger this code during the theme_switch action. And it does not seem to occur when I turn the theme on, only when I switch to something else (I know, it’s weird). I have read and I have attempted to follow the caveats mentioned at WordPress.org, for example putting two spaces between primary key and the definition. I have two other, similar, pieces of SQL code that generate the same error; all three were originally generated by phpMyAdmin so I know that they work.

Notice: Undefined offset: 1 in /Applications/MAMP/htdocs/wp-experiment/wp-admin/includes/upgrade.php on line 1463

Notice: Undefined offset: 1 in /Applications/MAMP/htdocs/wp-experiment/wp-admin/includes/upgrade.php on line 1463

Notice: Undefined offset: 1 in /Applications/MAMP/htdocs/wp-experiment/wp-admin/includes/upgrade.php on line 1463

WordPress database error: [Multiple primary key defined]
ALTER TABLE wp_stocks_0 CHANGE COLUMN id `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY

Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/wp-experiment/wp-admin/includes/upgrade.php:1463) in /Applications/MAMP/htdocs/wp-experiment/wp-includes/pluggable.php on line 897

In case I have misunderstood dbDelta, I should perhaps add, that the above code is executed several times.. so the table already exists. But if I understand dbDelta, that means it simply ought to do nothing because there is nothing in the db structure that needs changing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:51:51+00:00Added an answer on May 23, 2026 at 11:51 am

    Try —

    $sql1 = "CREATE TABLE `".$table_name1."` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `blogid` int(11) NOT NULL,
    `symbol` varchar(255) NOT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=MYISAM";
    

    In my experience, dbDelta is even fussier than alluded to in the Codex.

    Update
    From your edit, I would suggest you first check / only create the database if it doesn’t exist yet, which you can do using —

    global $wpdb;
    
    if ($wpdb->get_var("show tables like `" . $wpdb->prefix . $table_name1 . "`") != $wpdb->prefix . $table_name1) {
      // your dbDelta query here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the issue I am having: I have a large query that needs
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Here's the situation, i want to have a user that can enter time on
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's my scenario - I have an SSIS job that depends on another prior
Here's a coding problem for those that like this kind of thing. Let's see
Here is the scenario: I'm writing an app that will watch for any changes
Here's a strange question for you guys, I have a nice sorted list that
Here's a query that works fine: SELECT rowid as msg_rowid, a, b, c FROM
Here is my code sample, let me know if it can be further improved?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.