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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:40:45+00:00 2026-06-02T07:40:45+00:00

I am trying to create database tables and get them connected. I have ensured

  • 0

I am trying to create database tables and get them connected. I have ensured that my data types are identical. I also ensure that my tables are made before added the FK. Any advice would be greatly appreciated.

SQL query:

ALTER TABLE `Member` ADD FOREIGN KEY ( memberId ) REFERENCES `Order_Head` ( `memberId` ) ;

MySQL said: Documentation
#1005 - Can't create table 'test2.#sql-184c_63' (errno: 150) (Details...) 





-- ---
-- Table 'Order_Head'
-- 
-- ---

DROP TABLE IF EXISTS `Order_Head`;

CREATE TABLE `Order_Head` (
  `orderId` INTEGER NOT NULL AUTO_INCREMENT,
  `memberId` INTEGER NOT NULL,
  `date` DATE NOT NULL,
  PRIMARY KEY (`orderId`, `memberId`)
);

-- ---
-- Table 'Member'
-- 
-- ---

DROP TABLE IF EXISTS `Member`;

CREATE TABLE `Member` (
  `memberId` INTEGER NOT NULL AUTO_INCREMENT,
  `userName` VARCHAR(50) NOT NULL,
  `password` VARCHAR(50) NOT NULL,
  `email` VARCHAR(100) NOT NULL,
  `isAdmin` BOOLEAN NOT NULL DEFAULT false,
  PRIMARY KEY (`memberId`)
);

-- ---
-- Foreign Keys 
-- ---

ALTER TABLE `Member` ADD FOREIGN KEY (memberId) REFERENCES `Order_Head` (`memberId`);

-- ---
-- Table Properties
-- ---
ALTER TABLE `Order_Head` ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
ALTER TABLE `Member` ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
  • 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-02T07:40:47+00:00Added an answer on June 2, 2026 at 7:40 am

    It may be because the foreign key you are trying to set up is a primary key and has AUTO_INCREMENT, maybe what you meant was:

    ALTER TABLE `Order_Head` ADD FOREIGN KEY (memberId) REFERENCES `Member` (`memberId`);
    

    Any particular reason you’re not creating the foreign keys inside the CREATE TABLE statement? If not, then you should maybe do so too.

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

Sidebar

Related Questions

I'm trying to get data from the database in order to create a list
I'm trying to get data from database, and echo them on the page using
I'm trying to create a database with 12 different tables which has been working
I'm trying to create a basic database trigger that conditionally deletes rows from database1.table1
im trying to create a database for a feedback application in ASP.net i have
Consider a database(MSSQL 2005) that consists of 100+ tables which have primary keys defined
I have a mysql database on which I create users, and grant them select,
I have a large database made up of mixed data types (numeric, character, factor,
I am trying to create a database that can be used to store lots
I am trying to get a list of product id's that do not have

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.