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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:54:02+00:00 2026-06-17T06:54:02+00:00

I have the following tables: CREATE TABLE `OBL2`.`item` ( `itemID` INT NOT NULL AUTO_INCREMENT

  • 0

I have the following tables:

CREATE  TABLE `OBL2`.`item` (
`itemID` INT NOT NULL AUTO_INCREMENT ,
`itemName` VARCHAR(45) NOT NULL ,
PRIMARY KEY (`itemID`) ,
INDEX `itemName` (`itemName` ASC) );

CREATE  TABLE `OBL2`.`subject` (
`subjectID` INT NOT NULL ,
`subjectName` VARCHAR(45) NOT NULL ,
PRIMARY KEY (`subjectID`) );

Now since the connection is many to many, each item can have many subject and each subject can be related to many items – I’d like to set a connection table.
This is my code:

CREATE  TABLE `OBL2`.`itemsubjects` (
`itemID` INT NOT NULL ,
`subjectID` INT NOT NULL ,
PRIMARY KEY (`itemID`, `subjectID`) ,
INDEX `itemID_idx` (`itemID` ASC) ,
INDEX `subjectID_idx` (`subjectID` ASC) ,
CONSTRAINT `itemID`
FOREIGN KEY (`itemID` )
REFERENCES `OBL2`.`item` (`itemID` )
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `subjectID`
FOREIGN KEY (`subjectID` )
REFERENCES `OBL2`.`subject` (`subjectID` )
ON DELETE CASCADE
ON UPDATE CASCADE);

but for some reason the code of the 3rd table is not being accepted.
I get an error message:

ERROR 1005: Can’t create table ‘obl2.itemsubjects’ (errno: 121)

I’ve read about the error on the internet and it says it’s a known issue of MYSQL yet there are no solutions.

Any thoughts?

  • 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-17T06:54:03+00:00Added an answer on June 17, 2026 at 6:54 am

    The MySQL docs say in FOREIGN KEY Constraints (emphasis mine):

    If the CONSTRAINT symbol clause is given, the symbol value must be unique in the database. If the clause is not given, InnoDB creates the name automatically.

    So, the reason that the itemsubject table creation failed, was that you had another (foreign key) constraint, named itemID, or one named subjectID in some other table of the database.

    It’s good to have a naming conevntion that is standard across the database. Just as you have ColumnName_idx for indices, you can use ReferencedTable_ReferencingTable_FK for foreign key constraints:

    CREATE  TABLE OBL2.itemsubjects (
      itemID INT NOT NULL ,
      subjectID INT NOT NULL ,
      PRIMARY KEY 
        (itemID, subjectID) ,
      INDEX itemID_idx                           -- I like these 
        (itemID ASC) ,
      INDEX subjectID_idx                        -- two
        (subjectID ASC) ,
      CONSTRAINT item_itemsubject_FK             -- what I propose, here
        FOREIGN KEY (itemID)
        REFERENCES OBL2.item (itemID)
          ON DELETE CASCADE
          ON UPDATE CASCADE,
      CONSTRAINT subject_itemsubject_FK          -- and here 
        FOREIGN KEY (subjectID)
        REFERENCES OBL2.subject (subjectID)
          ON DELETE CASCADE
          ON UPDATE CASCADE
    ); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following tables CREATE TABLE `files` ( `fileid` int(11) NOT NULL AUTO_INCREMENT,
I have the following tables: CREATE TABLE `attendance_event_attendance` ( `id` int(11) NOT NULL AUTO_INCREMENT,
I have the following tables: CREATE TABLE `accommodations` ( `id` int(11) unsigned NOT NULL
With the following tables CREATE TABLE `Play` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id`
I have the following two tables: CREATE TABLE `table1` ( `ID` int(11) NOT NULL
Say I have the following 2 tables, CREATE TABLE t1( name VARCHAR(25) NOT NULL,
I have the following tables: CREATE TABLE `orders` ( `ID` varchar(5) NOT NULL, `IDUserProfile`
I have the following tables: CREATE TABLE members ( member_id int(1) unsigned NOT NULL
I have the following tables: create table TableA ( Id int primary key identity,
I have the following mysql tables: CREATE TABLE Articles ( ArticleID SMALLINT NOT NULL

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.