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

The Archive Base Latest Questions

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

I’m using a MySQL database. I have two tables, Table 1 and Table 2.

  • 0

I’m using a MySQL database. I have two tables, Table 1 and Table 2. There is a composite primary key in Table 1. There is a composite foreign key in Table 2 that references the Composite PK in Table 1.

The problem I have is illustrated below:

Table 1
|————PK———–|
menuid   | categoryid  | categoryname
1    |1     |myCategoryName1
1    |2     |myCategoryName2
2    |1     |myCategoryName3
2    |2     |myCategoryName4
2    |3     |myCategoryName5

I can create an entry in Table 2 that is referencing a false entry in Table 1:

Table 2
|————FK———–| |—-PK—-|
menuid  | categoryid  | postid |post name
1    |3     |1     |myPostName

Now, it’s not a big problem since I can insert valid values into the database. However, this seems like a relational error in the database and I would like to have a clean, correctly-functioning DB. Is there a way to correct this minor problem?

UPDATE: I was using phpMyAdmin to implement my database and apparently there is no way of implementing composite foreign keys in phpMyAdmin. I was able to look at my incorrectly-implemented foreign key via

SHOW CREATE TABLE Table2

where Table2 is the name of my second table with the composite foreign key.

Then I correctly added composite foreign key manually via

ALTER TABLE Table2 ADD CONSTRAINT my_fk_constraint
FOREIGN KEY (menuid, categoryid)
REFERENCES Table1(menuid, categoryid)

where my_fk_constraint is the name of the constraint being added.

Note: Manually adding foreign key constraints this way does not allow you to use a drop-down menu when inserting new entries (nor referring to the corrresponding table by clicking on the FK columns), as you would normally be able to in phpMyAdmin.

Thanks pst and thedayofcondor, you are both correct because I’m a small-dicked freak using phpMyAdmin.

  • 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-13T21:30:17+00:00Added an answer on June 13, 2026 at 9:30 pm

    Correct: no, prevent: yes!

    This should not happen if you set your constraints properly:
    http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I know there's a lot of other questions out there that deal with this
I have thousands of HTML files to process using Groovy/Java and I need to
I have a reasonable size flat file database of text documents mostly saved in
I have a view passing on information from a database: def serve_article(request, id): served_article

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.