$10 - MySQL import error. Multiple auto_increment

Discussion in 'MySQL' started by GeorgeB., May 12, 2008.

  1. #1
    OK I am importing a database from another server.

    I keep getting this error: Incorrect table definition; there can be only one auto column and it must be defined as a key

    It's doing that because every table in the mysql dump has an auto_increment ID column in it.

    Example

    1st table:
    CREATE TABLE ads (
    id int(10) NOT NULL auto_increment,
    name varchar(150) NOT NULL,
    ads_code text NOT NULL,
    remarks text NOT NULL,
    active_status enum('0','1') DEFAULT '1' NOT NULL,
    numofseen int(10) DEFAULT '0' NOT NULL,
    PRIMARY KEY (id)
    );

    Other Tables:

    DROP TABLE IF EXISTS announcement;
    CREATE TABLE announcement (
    id int(11) NOT NULL auto_increment,
    flag enum('0','1') DEFAULT '1' NOT NULL,
    text text NOT NULL
    );

    DROP TABLE IF EXISTS categories;
    CREATE TABLE categories (
    id int(10) NOT NULL auto_increment,
    name varchar(100) NOT NULL,
    display_name varchar(100),
    description varchar(200) NOT NULL,
    active_status enum('1','0') DEFAULT '1' NOT NULL,
    position int(10) DEFAULT '0' NOT NULL
    );


    $10 to anyone who can help me successfully import this database or tell me how I can fix this.
     
    GeorgeB., May 12, 2008 IP
  2. Agent_Smith

    Agent_Smith Well-Known Member

    Messages:
    890
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    145
    #2
    Try..

    CREATE TABLE ads(
    id int(10) NOT NULL auto_increment,
    PRIMARY KEY(id),
    name varchar(150) NOT NULL,
    ads_code text NOT NULL,
    remarks text NOT NULL,
    active_status enum('0','1') DEFAULT '1' NOT NULL,
    numofseen int(10) DEFAULT '0' NOT NULL
    );

    DROP TABLE IF EXISTS announcement;
    CREATE TABLE announcement (
    id int(11) NOT NULL auto_increment,
    PRIMARY KEY(id),
    flag enum('0','1') DEFAULT '1' NOT NULL,
    text text NOT NULL
    );

    DROP TABLE IF EXISTS categories;
    CREATE TABLE categories (
    id int(10) NOT NULL auto_increment,
    PRIMARY KEY(id),
    name varchar(100) NOT NULL,
    display_name varchar(100),
    description varchar(200) NOT NULL,
    active_status enum('1','0') DEFAULT '1' NOT NULL,
    position int(10) DEFAULT '0' NOT NULL
    );
     
    Agent_Smith, May 12, 2008 IP
  3. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #3
    Agent_Smith's queries are right.

    Just to clear the things, you must have to define the auto_increment column as Primary key.
     
    mwasif, May 13, 2008 IP