MySQL db problems

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fireorange
    Confirmed User
    • Jan 2005
    • 1648

    #1

    MySQL db problems

    I'm trying to create two foreign keys so that when I delete Gallery_ID 23 in the 'Galleries' table, it automatically deletes it in the 'Clicks' table but it isn't working.

    Code:
    CREATE TABLE `Galleries` (
    `Gallery_ID` INT NOT NULL AUTO_INCREMENT ,
    `Gallery_URL` VARCHAR( 255 ) NOT NULL ,
    `Category` VARCHAR( 50 ) NOT NULL ,
    PRIMARY KEY ( `Gallery_ID` ) 
    );
    
    CREATE TABLE `Trades` (
    `Trade_ID` INT NOT NULL AUTO_INCREMENT ,
    `Trade_Name` VARCHAR( 255 ) NOT NULL ,
    `Trade_URL` VARCHAR( 255 ) NOT NULL ,
    `Trade_Domain` VARCHAR( 255 ) NOT NULL ,
    PRIMARY KEY ( `Trade_ID` )
    );
    
    CREATE TABLE `Clicks` (
    `Gallery_ID` INT NOT NULL ,
    `Trade_ID` INT NOT NULL ,
    `Clicks` INT NOT NULL ,
    `Used` INT NOT NULL ,
    FOREIGN KEY ( `Gallery_ID` ) REFERENCES `Galleries` ( `Gallery_ID` ) ON UPDATE CASCADE ON DELETE CASCADE ,
    FOREIGN KEY ( `Trade_ID` ) REFERENCES `Trades` ( `Trade_ID` ) ON UPDATE CASCADE ON DELETE CASCADE 
    );
  • willow
    Confirmed User
    • Dec 2001
    • 131

    #2
    If your default table type isn't innodb, then add engine=innodb to the create statements.

    Comment

    • fireorange
      Confirmed User
      • Jan 2005
      • 1648

      #3
      Originally posted by willow
      If your default table type isn't innodb, then add engine=innodb to the create statements.
      I tried adding TYPE=InnoDB at the end but it gets created as INNODB everytime.

      Server version is: MySQL 3.23.58

      Is it enabled by default in that version? Any command to check?

      Comment

      • willow
        Confirmed User
        • Dec 2001
        • 131

        #4
        http://dev.mysql.com/doc/mysql/en/innodb-overview.html

        You probably need to enable it. Have a read. If you can, move to 4.1.x, much nicer.

        Comment

        • fireorange
          Confirmed User
          • Jan 2005
          • 1648

          #5
          Thanks I'll get my host to upgrade my server

          Comment

          • willow
            Confirmed User
            • Dec 2001
            • 131

            #6
            Make sure you dump your tables out before the upgrade, or some other kind of backup. Good luck.

            Comment

            • chompers
              Confirmed User
              • Jul 2005
              • 189

              #7
              bump for posterity's sake

              WOOOOOOOOOOOO WHOOOOOOOOOOOOOOOOOO!!!!!!!!!
              Make Money With The Best In the Biz

              Comment

              Working...