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

  • Home
  • SEARCH
  • 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 8945347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:13:35+00:00 2026-06-15T12:13:35+00:00

I am creating 3 tables in MySQL (Users, linkPosts, replyPosts) The first two tables

  • 0

I am creating 3 tables in MySQL (Users, linkPosts, replyPosts)

The first two tables are executed fine, but I got an error when I am trying to insert the SQL of the replyPosts. The following is the SQL code of the three tables:

The first table SQL code: works fine

CREATE TABLE Users ( 
userName VARCHAR (20) NOT NULL PRIMARY KEY,
password VARCHAR (20),
firstName VARCHAR (200),
lastName VARCHAR (200),
bio VARCHAR (160),
email VARCHAR (200),
country VARCHAR (200)
); 

The code of the second table: works fine

CREATE TABLE linkPosts ( 
linkPostID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
link VARCHAR(255),
linkDescription VARCHAR (140), 
linkPostTime TIMESTAMP,
userName VARCHAR (20),
FOREIGN KEY (userName) REFERENCES Users(userName));

The third table where the error appears:

CREATE TABLE replyPosts ( 
replyPostID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
reply VARCHAR (140), 
replyPostTime TIMESTAMP,
userName VARCHAR (20),
linkPostID INT,
FOREIGN KEY (linkPostID) REFERENCES linkPosts(linkPostID),
FOREIGN KEY (userName) REFERENCES Users(userName));

The error I got as follows:

Error 1005 : Can't create table 'mdb_aa847.replyPosts' (errno: 150)

I have searched and tried other people’s solutions but never worked. Any one can figure out where the error is?

Thanks in advance..

  • 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-15T12:13:35+00:00Added an answer on June 15, 2026 at 12:13 pm

    Does table replyPosts already exist? This error can happen in case you have duplicate foreign key names. use perror with the errno (in your case, its error 150), you should get:

    MySQL error code 150: Foreign key constraint is incorrectly formed
    

    After looking at your complete SQL, I think it is down to the fact that linkPostID is INT UNSIGNED when you create LinkPosts table, whereas in ReplyPosts table, linkPostID is INT. Change that to INT UNSIGNED and see if it works.

    As per the document here “foreign keys” should have the same size and sign, if it’s integer.

    As a side note, I would still insist on using UserId as primary key on Users table instead of UserName. Every time you insert a record in Users table, it will be sorted by UserName (since it is primary key, hence clustered index). Bigger the UserName field (Varchar(20)), the longer it takes for sorting the whole table. As your table grows, inserting records into User table is going to get cumbersome.

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

Sidebar

Related Questions

I need UNION two tables with creating new field, where 1 for first table,
When creating database tables I'm often stumped when trying to name my time/date/timestamp fields.
I've two routes, 1) creating sub-tables for each user and storing his individual content
I'm currently working on creating a private messaging system, (PHP/MySQL) in which users can
I'm very confused in creating Tables in MySQL because I read some PHP tutorials
I'm trying to optimize my PHP and MySQL, but my understanding of SQL databases
I have this alogirthm problem, in terms of creating mysql tables, let me explain
Our app would be creating dynamics forms for each users. We are considering two
I am trying to create a database with two tables: Location and UserProfile. Location
Is there way in MySQL to prevent someone from creating tables and/or databases 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.