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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:29:37+00:00 2026-05-26T00:29:37+00:00

MySQL 5.1.59 throws an error with this create table: CREATE TABLE IF NOT EXISTS

  • 0

MySQL 5.1.59 throws an error with this create table:

CREATE  TABLE IF NOT EXISTS `genre` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `abv` CHAR(3) CHARACTER SET 'latin1' COLLATE 'latin1_bin' NULL DEFAULT NULL ,
  `name` VARCHAR(80) NOT NULL DEFAULT '' ,
  `parent_id` INT NULL DEFAULT NULL ,
  PRIMARY KEY (`id`) ,
  INDEX `fk_genre_genre1` (`parent_id` ASC) ,
  CONSTRAINT `fk_genre_genre1`
    FOREIGN KEY (`parent_id` )
    REFERENCES `genre` (`id` )
    ON DELETE SET NULL
    ON UPDATE CASCADE)
ENGINE = InnoDB;

which was generated by MySQLWorkbench 5.2.33. The error message is:

ERROR 1005 (HY000) at line __: Can’t create table ‘mydb.genre’ (errno: 150)

What’s wrong with this create table?

The manual says:

If MySQL reports an error number 1005 from a CREATE TABLE statement,
and the error message refers to error 150, table creation failed
because a foreign key constraint was not correctly formed.

It also says that foreign key references to the same table are allowed:

InnoDB supports foreign key references within a table. In these cases,
“child table records” really refers to dependent records within the
same table.

The relationship I want is a non-identifying parent-child to represent a hierarchy of genres and sub-genres. A genre doesn’t have to have a parent, hence parent_id is nullable.

It may be relevant that MySQLWorkbench set the following:

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';
  • 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-26T00:29:38+00:00Added an answer on May 26, 2026 at 12:29 am

    Your column id is int unsigned; your column parent_id is int. Those don’t match. The solution is to change parent_id to be int unsigned as well.

    If you run the SHOW ENGINE InnoDB STATUS I put in a comment, you see this:

    11005 17:18:38 Error in foreign key constraint of table test/genre:
    
        FOREIGN KEY (`parent_id` )
        REFERENCES `genre` (`id` )
        ON DELETE SET NULL
        ON UPDATE CASCADE)
    ENGINE = InnoDB:
    Cannot find an index in the referenced table where the
    referenced columns appear as the first columns, or column types
    in the table and the referenced table do not match for constraint.
    Note that the internal storage type of ENUM and SET changed in
    tables created with >= InnoDB-4.1.12, and such columns in old tables
    cannot be referenced by such columns in new tables.
    See http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html
    for correct foreign key definition.
    

    Note the “column types in the table and the referenced table do not match” part.

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

Sidebar

Related Questions

I am using MYSQL 5.1. When i am going create a table, it throws
I have a table defined as follows: CREATE TABLE `mydb`.`users` ( `userID` int(10) unsigned
I have the following table in MYSQL: CREATE TABLE 't001_prospeccao' ( 'pro_id' bigint(20) NOT
I am trying to set sql_mode in MySQL but it throws an error. Command:
this is the error org.hibernate.hql.ast.QuerySyntaxException: Payment is not mapped [select p from Payment p]
I created a simple mysql database table using following query: CREATE TABLE customer( name
MySQL has this incredibly useful yet proprietary REPLACE INTO SQL Command. Can this easily
MySQL specifies the row format of a table as either fixed or dynamic, depending
MySQL 5.0.45 What is the syntax to alter a table to allow a column
mysql> select count(*) from table where relation_title='xxxxxxxxx'; +----------+ | count(*) | +----------+ | 1291958

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.