sql error errno: 121
Asked Answered
R

3

80
CREATE TABLE `users` (
  `UID` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `username` VARCHAR(45) NOT NULL ,
  `password` VARCHAR(100) NULL ,
  `name` VARCHAR(100) NULL ,
  `gender` BIT NULL ,
  `email` VARCHAR(255) NULL ,
  `phone` VARCHAR(30) NOT NULL ,
  `verified` BIT NOT NULL DEFAULT 0 ,
  `time_zone` INT NULL ,
  `time_register` DATETIME NULL ,
  `time_active` DATETIME NULL ,
  PRIMARY KEY (`UID`) ,
  UNIQUE INDEX `username_UNIQUE` (`username` ASC) ,
  INDEX `verified_INDEX` (`verified` ASC) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;


-- -----------------------------------------------------
-- Table `companies`
-- -----------------------------------------------------
CREATE TABLE `companies` (
  `CID` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `name` VARCHAR(45) NOT NULL ,
  `address` VARCHAR(100) NULL ,
  `email` VARCHAR(255) NULL ,
  `phone` VARCHAR(30) NULL ,
  `link` TEXT NULL ,
  `image_small` TEXT NULL ,
  `image_large` TEXT NULL ,
  `yahoo` VARCHAR(100) NULL ,
  `linkin` VARCHAR(100) NULL ,
  `twitter` VARCHAR(20) NULL ,
  `description` TEXT NULL ,
  `shoutout` VARCHAR(140) NULL ,
  `verified` BIT NOT NULL DEFAULT 0 ,
  PRIMARY KEY (`CID`) ,
  INDEX `name_INDEX` (`name` ASC) ,
  INDEX `verified_INDEX` (`verified` ASC) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;

-- -----------------------------------------------------
-- Table `products`
-- -----------------------------------------------------
CREATE TABLE `products` (
  `PID` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `CID` INT UNSIGNED NOT NULL ,
  `name` VARCHAR(100) NULL ,
  `description` TEXT NULL ,
  `image_small` TEXT NULL ,
  `image_large` TEXT NULL ,
  `tag` VARCHAR(45) NULL ,
  `price` DECIMAL(11,2) NULL ,
  PRIMARY KEY (`PID`) ,
  INDEX `tag_INDEX` (`tag` ASC) ,
  INDEX `company.cid_FK` (`CID` ASC) ,
  CONSTRAINT `company.cid_FK`
    FOREIGN KEY (`CID` )
    REFERENCES `companies` (`CID` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;

-- -----------------------------------------------------
-- Table `users_companies`
-- -----------------------------------------------------
CREATE TABLE `users_companies` (
  `UID` INT UNSIGNED NOT NULL ,
  `CID` INT UNSIGNED NOT NULL ,
  `role` INT UNSIGNED NULL ,
  PRIMARY KEY (`CID`, `UID`) ,
  INDEX `users.uid_FK` (`UID` ASC) ,
  INDEX `company.cid_FK` (`CID` ASC) ,
  CONSTRAINT `users.uid_FK`
    FOREIGN KEY (`UID` )
    REFERENCES `users` (`UID` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `company.cid_FK`
    FOREIGN KEY (`CID` )
    REFERENCES `companies` (`CID` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;

i got error

#1005 - Can't create table 'wew.users_companies' (errno: 121) (<a href="server_engines.php?engine=InnoDB&amp;page=Status&amp;token=3f35afdea97dd11f6b4ec1b669816738">Details...</a>) 

can anyone tell me which one is the problem ?

Ridley answered 23/7, 2010 at 8:10 Comment(0)
F
150

You have two constraints called company.cid_FK. Rename one.

Filmdom answered 23/7, 2010 at 8:14 Comment(1)
Why MySQL Workbench doesn't check for this is beyond me. :(Stodgy
A
48

For errors like this, you can find more information with 'perror'. i.e.

shell $ perror 121

MySQL error code 121: Duplicate key on write or update
Win32 error code 121: The semaphore timeout period has expired.

Aho answered 24/7, 2010 at 2:53 Comment(1)
Unless you're on a Windows machine. :-(Gudrun
P
-1

I got the same error MySQL error code 121: Duplicate key on write or update.

although I deleted the table from my database to recreated again but I could not so I recreated the table yet with different constrain.

I found that the old constrain is still there.

Perspiration answered 16/5, 2020 at 14:26 Comment(1)
Is this a solution or are you saying you have the same situation?Fortyish

© 2022 - 2024 — McMap. All rights reserved.