php – Make id column as AUTO INCREMENT on plugin activation

Question

I am creating a wordpress plugin in which I am creating a table, the table is getting generated successfully on activating the plugin but the problem is, column id is not generating as AUTO INCREMENT

public static function activate()
    {


    global $wpdb;

    $sql = "CREATE TABLE `{$wpdb->base_prefix}employee` (
    `id` int NOT NULL,
    `name` varchar(255) NOT NULL,
    `dob` date NOT NULL,
    `gender` int NOT NULL,
    `email` varchar(255) NOT NULL,
    `joining_date` date NOT NULL,
    `address` varchar(255) NOT NULL,
    `salary_package` int NOT NULL,
    `marital_status` int NOT NULL,
    `department` varchar(255) NOT NULL,
    `designation` varchar(255) NOT NULL,
    PRIMARY KEY (id)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci AUTO_INCREMENT=1;
  COMMIT;";

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

0
sanad qazi 4 months 2022-04-09T02:01:31-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse