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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:22:46+00:00 2026-06-08T05:22:46+00:00

Many people had this problem already, but there was no fitting solution in other

  • 0

Many people had this problem already, but there was no fitting solution in other posts.

I have two tables, one named “sales”, the other named “host_flags”. I would like to have a foreign key for host_flags.sales_id to sales.id, but mysql won’t let me! I have primary indexes defined in each table, so I wonder why…

The host_flags table already has a foreign key on the column host_id, but even when I tried and created the foreign key for the sales id first, it wouldn’t let me.

The tables look like:

CREATE TABLE `sales` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `email` varchar(255) DEFAULT NULL,
  `password` varchar(255) DEFAULT NULL,
  `creation` datetime DEFAULT NULL,
  `lastupdate` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

CREATE TABLE `host_flags` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `host_id` int(11) DEFAULT NULL,
  `sales_id` int(11) DEFAULT NULL,
  `creation` datetime DEFAULT NULL,
  `lastupdate` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `host_id6` (`host_id`),
  CONSTRAINT `host_id6` FOREIGN KEY (`host_id`) REFERENCES `hosts` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `hosts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `creation` datetime NOT NULL,
  `lastupdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=32225 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

I get this error message:

MySQL said: Can't create table 'primarydata.#sql-191_1' (errno: 150)

Thanks!

Charles

SOLUTION FOUND

All ints of the primary indexes have to be either signed or unsigned – not mixed.

  • 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-08T05:22:47+00:00Added an answer on June 8, 2026 at 5:22 am

    Typically:

    I like to declare the FK constraints outside of the table definition after all tables have been constructed.

    ALTER TABLE `tbl`
        ADD CONSTRAINT `constr`
            FOREIGN KEY `fk_id` REFERENCES `ftbl`(`id`)
                ON UPDATE CASCADE
                ON DELETE CASCADE;
    

    This way I can make sure the problem isn’t something like the datatype of tbl.fk_id not being the same as the one of ftbl.id (including UNSIGNED as @Devart said). Or not having declared ftbl.id as unique. Regardless of the order of declaration of the tables.

    After i do this i can integrate the constraint back into the table definition and take into account the order in which the tables need to be created to allow the constraint to be added.

    You problem:

    -- creating the sales table
    `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
    
    -- creating the host_flags table
    `sales_id` int(11) DEFAULT NULL,
    
    -- the sales.id is declared as unsigned
    -- the host_flags.sales_id is declared signed
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that many people have had this problem... but I am now having
Here's something interesting, turnsout that many people out there had this problem, but i
I know many people have had this problem and I have searched Google/Stack Overflow,
I see that many people get this error, but their situations all appear a
I know many people ask this but all the answers are specific apps so
I am experiencing the same problem as many people have asked about before, where
Many people have the same problem, the R file. In my case, i have
Many people use this method to add animation on switching views. When I try
Many people have argued about function size. They say that functions in general should
Like many people, I have several SVN repositories that contains several projects. I've decided

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.