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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:08:46+00:00 2026-06-04T17:08:46+00:00

I am stuck with this error no 150 problem in mysql and I know

  • 0

I am stuck with this error no 150 problem in mysql and I know there have been questions
which discuss this problem but I still can’t find where I am wrong. Here is the database I am trying to create:

create table business (
    ident varchar(40) NOT NULL,
    name varchar(50) NOT NULL,
    rating INT UNSIGNED NOT NULL,
    PRIMARY KEY(ident)
) ENGINE=InnoDB;

create table deals (
    business_id varchar(40) NOT NULL,
    deals_id varchar(20) NOT NULL,
    deals_title varchar(50) NOT NULL,
    PRIMARY KEY (business_id, deals_id),
    FOREIGN KEY (business_id) REFERENCES business(ident) ON DELETE CASCADE
) ENGINE=InnoDB;

create table d_options (
    business_id varchar(40) NOT NULL,
    dealid varchar(20) NOT NULL,
    option_title varchar(40) NOT NULL,
    PRIMARY KEY(business_id, dealid, option_title), 
    FOREIGN KEY(business_id) REFERENCES business(ident) ON DELETE CASCADE,
    FOREIGN KEY(dealid) REFERENCES deals(deals_id) 
) ENGINE=InnoDB;

I get error: ERROR 1005 (HY000): Can’t create table ‘test.d_options’ (errno: 150)

I know for foreign key constraints to be satisfied there should be a index in the parent table as per mysql documentation, but I think that there is by default indexing
on primary key.

The result of innodb status is:

120530  0:47:48 Error in foreign key constraint of table test/d_options:
FOREIGN KEY(dealid) REFERENCES deals(deals_id) 
) 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.

Any help is appriciated.

  • 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-04T17:08:47+00:00Added an answer on June 4, 2026 at 5:08 pm

    You have a compound primary key on (business_id, deal_id) and they are indexed as a pair, but to satisfy the FK, you need another index on deal_id alone:

    create table deals (
        business_id varchar(40) NOT NULL,
        deals_id varchar(20) NOT NULL,
        deals_title varchar(50) NOT NULL,
        PRIMARY KEY (business_id, deals_id),
        FOREIGN KEY (business_id) REFERENCES business(ident) ON DELETE CASCADE,
        /* Add an index on deals_id, separate from the compound PK */
        INDEX idx_deals_id (deals_id)
    ) ENGINE=InnoDB;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may be a simple problem. But im totally stuck with this error. I
I've been stuck on this EXC_BAD_ACCESS error 2 days now. I have a reloadAnnotations
Im stuck with this little project in C# but basically my problem is this:
I have been stuck on this for days, and was wondering if anyone had
I've been stuck with this for weeks now and have no idea where I'm
I've been stuck with this error for quite a while now and I just
I have this problem with Headers already sent with Magento. I get this error:
I'm relatively new to shell scripting and I've been stuck on this error for
Evening folks!! Stuck with this rather dull problem. I have deployed my website on
I'm stuck with this. I'm self studying assenbler and translating some basics instructions. But

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.