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 8696829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:21:39+00:00 2026-06-13T01:21:39+00:00

Just trying to create a new database table on plugin activation. For the love

  • 0

Just trying to create a new database table on plugin activation.
For the love of life I cannot figure out why this will not work.

function super_simple_photo_activate() {
global $wpdb;
$table_name = $wpdb->prefix."super_simple_photo_options";
if ($wpdb->get_var('SHOW TABLES LIKE '.$table_name) != $table_name) {
    $sql = 'CREATE TABLE '.$table_name.'(
        thumbs_max VARCHAR(3),
        image_max VARCHAR(4),
        image_quality VARCHAR(3),
        PRIMARY KEY  (id))';

    require_once(ABSPATH.'wp-admin/includes/upgrade.php');
    dbDelta($sql);

    add_option("super_simple_photo_db_version", "1.0");
}
}
register_activation_hook(__FILE__, 'super_simple_photo_activate');

I’ve spent at least 5 hours tinkering with this but with no luck, no error either on activation.

What did the trick – id INTEGER NOT NULL – thanks t.thielemans

$sql = 'CREATE TABLE '.$table_name.'(
        id INTEGER NOT NULL,
        thumbs_max VARCHAR(3),
        image_max VARCHAR(4),
        image_quality VARCHAR(3),
        PRIMARY KEY  (id))';
  • 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-06-13T01:21:41+00:00Added an answer on June 13, 2026 at 1:21 am

    Your create table syntax is wrong, should be:

     $sql = 'CREAT TABLE '.$table_name.'(
    -----
     $sql = 'CREATE TABLE '.$table_name.'(
    

    Edit: Define your primary key

     $sql = 'CREATE TABLE '.$table_name.'(
            id INTEGER NOT NULL,
            thumbs_max VARCHAR(3),
            image_max VARCHAR(4),
            image_quality VARCHAR(3),
            PRIMARY KEY (id))';
    

    Bit of extra info on SQL from W3schools: http://www.w3schools.com/sql/sql_primarykey.asp

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is just a simple question. I was trying to create a new object
I am trying to execute a sql query which will create a new table
This is driving me wild with frustration. I am just trying to create a
I created a new Rails API app. I am trying to create the database
I am just trying to add data to the database and retrieve it. This
I'm trying to create a efficient query which will retrieve 'projects' from a database
I'm new to Entity Framework and am trying to figure things out. I have
I am trying to create some pages using PHP / MySQL. My database table
I'm trying to create a new table in postgres but when I do it
I'm trying to create a table in android database, but when i try to

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.