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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:55:13+00:00 2026-06-10T15:55:13+00:00

I created the master table with the composite primary key. parent table structure is

  • 0

I created the master table with the composite primary key.

parent table structure is as follows:

CREATE TABLE `taskcategory` (
  `SiteID` int(10) unsigned NOT NULL DEFAULT 1,
  `TaskID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `TaskName` varchar(45) DEFAULT '',
  `TaskDescription` varchar(45) DEFAULT '',
  `IsInbuild` int(11) DEFAULT '1',
  PRIMARY KEY (`TaskID`,`SiteID`)
);

when i am trying to create the table with foreign key with the above parent table reference i am getting ‘can’t create table error no 150’ error . help me to do that.

child table structure as follows:

CREATE TABLE taskdetails (`SiteID` int(10) unsigned NOT NULL DEFAULT '1',
  `TaskID` int(10) unsigned NOT NULL DEFAULT '0',
  `SubtaskID` int(10) unsigned NOT NULL,
  `ScriptName` varchar(255) DEFAULT '',
  `FunctionName` varchar(255) DEFAULT '',
  `ButtonName` varchar(255) DEFAULT '',
  `IsInbuild` int(10) unsigned DEFAULT '1',
  `Description` varchar(255) DEFAULT '',
  PRIMARY KEY (`SubtaskID`,`TaskID`,`SiteID`),
                            INDEX (siteid, taskid),
                            FOREIGN KEY (siteid, taskid)
                              REFERENCES taskcategory(siteid, taskid)
                              ON UPDATE CASCADE ON DELETE CASCADE
                            ) ENGINE=INNODB;

help me to resolve it.

  • 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-10T15:55:15+00:00Added an answer on June 10, 2026 at 3:55 pm

    From the manual:

    InnoDB requires indexes on foreign keys and referenced keys so that
    foreign key checks can be fast and not require a table scan. In the
    referencing table, there must be an index where the foreign key
    columns are listed as the first columns in the same order. Such an
    index is created on the referencing table automatically if it does not
    exist. This index might be silently dropped later, if you create
    another index that can be used to enforce the foreign key constraint.
    index_name, if given, is used as described previously.

    So when you add an index in the parent table it works (yes, I tested it):

    CREATE TABLE `taskcategory` (
      `SiteID` int(10) unsigned NOT NULL DEFAULT 1,
      `TaskID` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `TaskName` varchar(45) DEFAULT '',
      `TaskDescription` varchar(45) DEFAULT '',
      `IsInbuild` int(11) DEFAULT '1',
      PRIMARY KEY (`TaskID`,`SiteID`)
      , INDEX (SiteID, TaskID)
    ) ENGINE=INNODB;
    
    CREATE TABLE taskdetails (`SiteID` int(10) unsigned NOT NULL DEFAULT '1',
      `TaskID` int(10) unsigned NOT NULL DEFAULT '0',
      `SubtaskID` int(10) unsigned NOT NULL,
      `ScriptName` varchar(255) DEFAULT '',
      `FunctionName` varchar(255) DEFAULT '',
      `ButtonName` varchar(255) DEFAULT '',
      `IsInbuild` int(10) unsigned DEFAULT '1',
      `Description` varchar(255) DEFAULT '',
      PRIMARY KEY (`SubtaskID`,`TaskID`,`SiteID`)
                                ,INDEX (SiteID, TaskID)
                                ,FOREIGN KEY (SiteID, TaskID)
                                  REFERENCES taskcategory(SiteID, TaskID)
                                  ON UPDATE CASCADE ON DELETE CASCADE
                                ) ENGINE=INNODB;
    

    You have a primary key on those columns already (which means there’s an implicit index), but the order of the columns is important!

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

Sidebar

Related Questions

With the following DB schema: CREATE TABLE master ( id integer primary key autoincrement,
I user Master-Detail created a project. On the MasterViewController , the table cell i
I have a parent master table that is generic enough to hold the common
I have created split view based ipad app, where master view is table view
I have a table voucher_master. I want to make composite unique key which satisfies
I read somewhere that if we create a table in master db by using
I have a master/detail ClientDataSet as follows (these are created/populated at run-time and populated
I've created a master page that uses 3 instances of System.Web.UI.WebControls.AdRotator each backed by
I've created a Master-Detail Application with Xcode 4.3. In the Master View I want
I have a web application in Asp.Net. I've created my master page and inside

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.