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 333303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:56:55+00:00 2026-05-12T09:56:55+00:00

Ok, so I am creating tables in MySQL with indexes and foreign keys. I

  • 0

Ok, so I am creating tables in MySQL with indexes and foreign keys. I use MySQL Workbench to create the tables and then have it forward engineer a SQL create script (I do better in a visual DB environment than just writing out the SQL code by hand right away).

The problem is many times when I import the sql script into mysql, I get the classic eror:

#1005 - Can't create table 'db.tablename' (errno: 121) 

I’ve managed to figure out the problem each time, usually index/foreign key related, but now I’m starting to get irritated at having to fix it each time. I don’t really understand what the problem is (especially when a MySQL product is creating sql code for its own database). Below is some code that typically causes the problem.

CREATE  TABLE IF NOT EXISTS `db`.`groupMembers` (
  `groupMembersID` INT NOT NULL AUTO_INCREMENT ,
  `groupID` INT NOT NULL ,
  `userID` INT NULL ,
  PRIMARY KEY (`groupMembersID`) ,
  INDEX `group` (`groupID` ASC) ,
  INDEX `user` (`userID` ASC) ,
  CONSTRAINT `group`
    FOREIGN KEY (`groupID` )
    REFERENCES `db`.`groups` (`groupsID` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `user`
    FOREIGN KEY (`userID` )
    REFERENCES `db`.`users` (`usersID` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;

The error usually comes from the first INDEX definition – even when I take out the index definition, I just get the error at the the first foreign key constraint definition. I’ve checked, and the foreign key remote column and the local column are the same data-type and size.

  • 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-05-12T09:56:56+00:00Added an answer on May 12, 2026 at 9:56 am

    “errno 121 means a duplicate key error”

    Constraints must have an unique name in the database, you might wanna change your FK names. Like so, FK_groupMembers_group and FK_groupMembers_user.

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

Sidebar

Related Questions

New to mysql and have been told by many, that creating foreign keys in
I have installed mysql Query browser for creating tables/ views/ procedures (In Ubuntu) But
I have this alogirthm problem, in terms of creating mysql tables, let me explain
I have tried creating my mysql tables with both UTF-8 and Latin1 Char sets.
I am trying to have 2 tables with crossed foreign keys, but I am
Hi Following is the syntax for creating table in mysql. I want to create
I'm creating a Web interface for a table in Mysql and want to use
I'm creating tables in SQL Server > Diagram view, i just find it easier
I'm working with a contract developer who is starting to create tables (MySQL) without
I'm trying to speed up SELECT queries in MySQL tables which already have some

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.