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

  • SEARCH
  • Home
  • 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 9191619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:43:41+00:00 2026-06-17T20:43:41+00:00

I am trying to set up a foreign key in Mysql workbench. I used

  • 0

I am trying to set up a foreign key in Mysql workbench. I used the same name for the foreign key as the primary key of the table I am trying to set a relationship with. I already have one relation set up this way in another table, but When I try and apply the alterations to this table, the script gives me an error:

Error 1005: Can’t create table ‘X.#sql-718_a’ (errno: 121)

SQL Statement:

ALTER TABLE `X`.`X_use`    
ADD CONSTRAINT `XyzID`   
FOREIGN KEY (`XyzID` )   REFERENCES `X`.`Xyz` (`XyzID` )   
ON DELETE NO ACTION   O
N UPDATE NO ACTION , 
ADD INDEX `XyzID` (`XyzID` ASC)  , 

However, if I change the foreign key name to “AbcID” I have no problem setting up the foreign key relation. Why is that and why can’t I have the primary key name from one table be the same for the foreign key for this table? I have set up relations like that previously but for this table I cannot.

  • 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-17T20:43:43+00:00Added an answer on June 17, 2026 at 8:43 pm

    Constraint names have to be unique within the database.

    That (errno: 121) in the error message means that MySQL encountered a duplicate key exception. The usual cause of this is that there is already a constraint of the same name in the database.

    This “unique name” requirement is one reason why the normative pattern is to include the table name when constructing the name of the foreign key constraint. e.g. FK_table_cols e.g. FK_X_use_XyzID.

    Why must the constraint name be unique within the database? That’s a question for the dbms designers.

    But consider this: when the database encounters a constraint violation, it throws an error that contains the name of the constraint. When that constraint name references only one constraint in the database, that makes locating the problem a bit easier.

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

Sidebar

Related Questions

I am trying to set a foreign key relationship between an Order_Items table and
I'm trying to set up a foreign key relationship with JPA annotations and generate
In a Rails app, I have foreign key constraints in MySQL which I set
I have a database already set up. I am trying to change the collation
I was wrestling with mysql administrator trying to change the primary key on a
I am trying to set up a DataRelation between two mysql Tables. The parent-table
I need help trying set-up Foreign Keys after having difficulty following Music library MySQL
I have a Linq to SQL EntitySet with a Foreign Key Relationship between two
I'm trying to set up a multi-select filter on a foreign key in the
I'm having a problem with foreign key in mysql.I'm trying to insert a row

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.