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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:22:30+00:00 2026-05-24T06:22:30+00:00

I have a table that references a reservation and a product, but I can’t

  • 0

I have a table that references a reservation and a product, but I can’t add any foreign key.

Here is the table :

CREATE TABLE IF NOT EXISTS `resa_product` (
  `id_reservation` int(10) NOT NULL,
  `id_business` int(10) NOT NULL,
  `id_category` int(10) NOT NULL,
  `id_product` int(10) NOT NULL,
  `quantity` int(11) NOT NULL,
  PRIMARY KEY (`id_reservation`,`id_business`,`id_category`,`id_product`),
  KEY `resa_prod_index` (`id_business`,`id_category`,`id_product`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

The product table :

CREATE TABLE IF NOT EXISTS `product` (
  `id_business` int(10) NOT NULL,
  `id_product` int(10) NOT NULL AUTO_INCREMENT,
  `id_category` int(10) NOT NULL,
  `nom` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
 ...
  PRIMARY KEY (`id_product`,`id_category`,`id_business`),
  KEY `id_category` (`id_category`),
  KEY `id_business` (`id_business`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=5 ;

but when I try this, I get the errno 150 from mySQL :

ALTER TABLE `resa_product`
ADD FOREIGN KEY (`id_business`, `id_category`, `id_product`)
REFERENCES `product`(`id_business, `id_category`, `id_product`)
ON UPDATE CASCADE
ON DELETE RESTRICT;

I don’t understand why I can’t insert this composed key, although I added an index. Do someone has an idea ?

thanks for your help

  • 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-24T06:22:30+00:00Added an answer on May 24, 2026 at 6:22 am

    In the product table

    • data type and collation of the 3 columns must match
    • there must be a unique constraint or index on the 3 columns in the same order as the FK

    Edit: after question update.

    Change the foreign key to this to align column order to the PK of product

    ALTER TABLE `resa_product`
    ADD FOREIGN KEY (`id_product`, `id_category`, `id_business`)
    REFERENCES `product`(`id_product, `id_category`, `id_business`)
    ON UPDATE CASCADE
    ON DELETE RESTRICT;
    

    However, the 3 columns appear in different orders all over the show. I’d fix this to be consistent personally…

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

Sidebar

Related Questions

I have a table containing primary key and foreign key that references same table.
I have table A(id). I need to create table B(id) add a foreign key
If I have table B with foreign key references to table A (set to
Hi, I have a table that contains a foreign key value(id). This field is
I have a table that self references to create a hierarchy. CREATE TABLE [dbo].[Topics](
I have a table that looks like this: CREATE TABLE foobar ( id SERIAL
I have a table that stores two foreign keys, implementing a n:m relationship. One
So I have a table that holds references to other tables like: local a
I have an application that works with a database that uses foreign key constraints.
I have a table that has two foreign keys to two different tables with

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.