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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:16:46+00:00 2026-05-23T11:16:46+00:00

I find innodb quite annoying when I try to design a db structure, at

  • 0

I find innodb quite annoying when I try to design a db structure, at least compared with MyIsam, which seems to have less limitations

Say, if I want to create a simple library system.
And I have four tables.

1,table book_item, which records the book_name, author, publish time and those basic information about books

2, table book, which represents a specific real object of the book item. So a book_item object can relate to many book objects.

3, table tag, which represents a book tag. Like science, literature, architecture and so on.

4, table tag_book_item_relation, which relates tags to book_items.

So, the relations are as below.

1,we have a book item to book is one-to-many relationship

2,book_item to tag is many-to-many relationship.

Note here, engine for the table are all innodb
If I try to create the tables, it will fail:

Error:
Executing SQL script in server
ERROR: Error 1005: Can't create table 'yet_another_test.book' (errno: 121)

However, if I change the engine of book or tag_book_item_relation to MyISAM, everything will be fine.

So, I am wondering what is going wrong if I use engine innodb for tablebook and tag_book_item_relation

The sql script is here(forward engineering in MySQL workbench):

CREATE  TABLE IF NOT EXISTS `yet_another_test`.`tag` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  PRIMARY KEY (`id`) ,
  UNIQUE INDEX `id_UNIQUE` (`id` ASC) )
ENGINE = InnoDB;

CREATE  TABLE IF NOT EXISTS `yet_another_test`.`book_item` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  PRIMARY KEY (`id`) ,
  UNIQUE INDEX `id_UNIQUE` (`id` ASC) )
ENGINE = InnoDB;

CREATE  TABLE IF NOT EXISTS `yet_another_test`.`tag_book_item_relation` (
  `book_item_id` INT NOT NULL ,
  `tag_id` INT NOT NULL ,
  PRIMARY KEY (`book_item_id`, `tag_id`) ,
  INDEX `fk_tag` (`tag_id` ASC) ,
  INDEX `fk_book_item` (`book_item_id` ASC) ,
  CONSTRAINT `fk_tag`
    FOREIGN KEY (`tag_id` )
    REFERENCES `yet_another_test`.`tag` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_book_item`
    FOREIGN KEY (`book_item_id` )
    REFERENCES `yet_another_test`.`book_item` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

CREATE  TABLE IF NOT EXISTS `yet_another_test`.`book` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `book_item_id` INT NOT NULL ,
  PRIMARY KEY (`id`, `book_item_id`) ,
  INDEX `fk_book_item` (`book_item_id` ASC) ,
  UNIQUE INDEX `id_UNIQUE` (`id` ASC) ,
  CONSTRAINT `fk_book_item`
    FOREIGN KEY (`book_item_id` )
    REFERENCES `yet_another_test`.`book_item` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;
  • 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-23T11:16:47+00:00Added an answer on May 23, 2026 at 11:16 am

    Create your tables without the Foreign Key constraints. Although the same statements work with MyISAM engine, the constraints are silently ignored there – that is why you are not getting the errors. If you really need those constraints, then create them correctly. However, I generally tend to avoid FK constraints and implement the constraints at application level.

    One problem I spot right away are the symbols of your constraints which have to be unique at DB level and you have fk_book_item both on tag_book_item_relation table and on book table

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

Sidebar

Related Questions

How to find mysql databases/tables, which are stored in innodb engine? Show tables just
I have a mySQl innodb database which has a couple of tables which store
find whether there is a loop in a linked list. Do you have other
I find the code in an old common lisp book, and try it in
I have an incredibly simple query (table type InnoDb) and EXPLAIN says that MySQL
I am curious to find out what people think, we have a very small
I have a MySql db with innoDB tables. Very simplified this is how two
I have a question regarding Foreign Keys in an InnoDB Table. I have 4
I'm reorganizing our MySQL database, changing MyISAM tables to InnoDB and setting foreign keys,
Here's some background info. I have three MySQL tables (all InnoDB). The first table

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.