MySQL Forums
Forum List  »  InnoDB

Multiple columns UK problem
Posted by: a a
Date: September 25, 2008 06:28PM

I have a table that works fine like this:
id_table -> PK
id_quadra, id_setor_FK -> UK

CREATE  TABLE IF NOT EXISTS `sic`.`quadra` (
  `table_id` INT NOT NULL AUTO_INCREMENT ,
  `id_quadra` INT NOT NULL ,
  `id_setor_FK` INT NOT NULL ,
  PRIMARY KEY (`table_id`) ,
  INDEX `id_quadra_setor_FK` (`id_setor_FK` ASC) ,
  UNIQUE INDEX `id_quadra_UK` (`id_quadra` ASC, `id_setor_FK` ASC) ,
  CONSTRAINT `id_quadra_setor_FK`
    FOREIGN KEY (`id_setor_FK` )
    REFERENCES `sic`.`setor` (`table_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

But If I add another FK (id_bairro_FK) that has nothing to do with the code above, it gives me error 150.

CREATE  TABLE IF NOT EXISTS `sic`.`quadra` (
  `table_id` INT NOT NULL AUTO_INCREMENT ,
  `id_quadra` INT NOT NULL ,
  `id_setor_FK` INT NOT NULL ,
  `id_bairro_FK` INT NULL ,
  `mapa` BLOB NULL ,
  PRIMARY KEY (`table_id`) ,
  INDEX `id_quadra_bairro_FK` (`id_bairro_FK` ASC) ,
  INDEX `id_quadra_setor_FK` (`id_setor_FK` ASC) ,
  UNIQUE INDEX `id_quadra_UK` (`id_quadra` ASC, `id_setor_FK` ASC) ,
  CONSTRAINT `id_quadra_bairro_FK`
    FOREIGN KEY (`id_bairro_FK` )
    REFERENCES `sic`.`bairro` (`id_bairro` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `id_quadra_setor_FK`
    FOREIGN KEY (`id_setor_FK` )
    REFERENCES `sic`.`setor` (`table_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

What the hell maybe hapenning?

Options: ReplyQuote


Subject
Views
Written By
Posted
Multiple columns UK problem
4467
a a
September 25, 2008 06:28PM
3338
October 04, 2008 11:32PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.