Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7788629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:03:38+00:00 2026-06-01T21:03:38+00:00

Good day I’m trying to solve an issue with foreign key relationship between three

  • 0

Good day

I’m trying to solve an issue with foreign key relationship between three tables. Basically I have two secondary tables, each one has two foreign keys and each foreign key is referenced to a single primary key in the third table.

This same issue happens in a much larger database, however due to its complexity, size and possible copyright issues. I had no choice but to isolate the problem and create a replica that would result in the same issue. However if you must know, the same two tables that reference the main table People are just two in a universe of dozens of the same kind in the database in question.

My hope is that someone can point the problem and maybe provide a solution that wouldn’t effect much of the current structure, so that I can apply it myself, probably to all other tables because from what I see of the database diagram, its likely they will all suffer from the same problem. Database authorship is not mine, which only adds to one’s confusion when looking at the diagram.

The SQL create script:

CREATE SCHEMA IF NOT EXISTS `sampleBD` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
USE `sampleBD` ;

-- -----------------------------------------------------
-- Table `sampleBD`.`People`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `sampleBD`.`People` (
  `PeopleID` INT NOT NULL AUTO_INCREMENT ,
  `Name` VARCHAR(200) NOT NULL ,
  `EntryDate` DATETIME NULL ,
  `EntryBy` INT NULL ,
  PRIMARY KEY (`PeopleID`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `sampleBD`.`PeopleNumberId`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `sampleBD`.`PeopleNumberId` (
  `PeopleNumberIdID` INT NOT NULL AUTO_INCREMENT ,
  `PeopleID` INT NOT NULL ,
  `NumberId` INT(11) NOT NULL ,
  `EntryDate` DATETIME NULL ,
  `EntryBy` INT NULL ,
  PRIMARY KEY (`PeopleNumberIdID`) ,
  INDEX `PeopleID` (`PeopleID` ASC) ,
  INDEX `EntryBy` (`EntryBy` ASC) ,
  CONSTRAINT `PeopleID`
    FOREIGN KEY (`PeopleID` )
    REFERENCES `sampleBD`.`People` (`PeopleID` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `EntryBy`
    FOREIGN KEY (`EntryBy` )
    REFERENCES `sampleBD`.`People` (`PeopleID` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `sampleBD`.`PeopleCbi`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `sampleBD`.`PeopleCbi` (
  `PeopleCbiID` INT NOT NULL AUTO_INCREMENT ,
  `PeopleID` INT NOT NULL ,
  `Cbi` INT NOT NULL ,
  `EntryDate` DATETIME NULL ,
  `EntryBy` INT NULL ,
  PRIMARY KEY (`PeopleCbiID`) ,
  INDEX `PessoaID` (`PeopleID` ASC) ,
  INDEX `EntryBy` (`EntryBy` ASC) ,
  CONSTRAINT `PessoaID`
    FOREIGN KEY (`PeopleID` )
    REFERENCES `sampleBD`.`People` (`PeopleID` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `EntryBy`
    FOREIGN KEY (`EntryBy` )
    REFERENCES `sampleBD`.`People` (`PeopleID` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

The script is able to create the first and second tables, however when it reaches the third table it returns an error code.

Error Code: 1005. Can't create table 'samplebd.peoplecbi' (errno: 121)

It’s a foreign key problem, but I’m not sure how it could be fixed without altering the current structure of the table or tables involved.

Thanks for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:03:40+00:00Added an answer on June 1, 2026 at 9:03 pm

    This looks like a name conflict between foreign key constraint names. Constraint names must be unique in a database, like table names are.

    So just choose another name for the constraint EntryBy in the 3rd table. It will not affect any of the functionality you have.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day, I am having an issue trying to get the Text on a
Good Day, I have two connection strings defined in my web.config file. <connectionStrings> <add
Good day pythonistas and the rest of the coding crowd, I have two QMainWindows
Good day, I'm having a problem with asp.net 2.0 viewstate. Basically, I want to
Good Day All we are trying to do is inside a trigger make sure
Good day. I have little usage of Flash CS4, however i have to build
Good day, I have a gen_server process which does some long-running state-updating tasks periodically
Good day, to stackoverflow community. I have run into a bug with regard to
Good day I have a basic toolbar to which I added ImageIcon buttons. The
Good day everyone. I have a question about making and using derived classes of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.