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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:34:18+00:00 2026-06-12T16:34:18+00:00

I’m trying to design a database for a little project I am working on

  • 0

I’m trying to design a database for a little project I am working on in PHP. I don’t have much experience working with databases (as you will soon notice) so right now I’ve thrown myself a little in the deep end.

I’m developing a database that will be the foundation for a basic stats system I am writing in PHP. I have concluded that I will need (at least) 3 tables.

TOURNAMENT – > One tournament has many matches

tournamentID SMALLINT UNSIGNED PRIMARY KEY, 

MATCH -> One match has many players

tournamentID SMALLINT UNSIGNED,
matchID SMALLINT UNSIGNED,

PLAYER -> One player has many matches and many tournaments

tournamentID SMALLINT UNSIGNED,
matchID SMALLINT UNSIGNED,
playerID SMALLINT UNSIGNED,

My attempt to create this database:

<?php
//Connect
$link = mysql_connect("localhost", "root", "password") or die(mysql_error());
mysql_select_db("stats") or die(mysql_error());

//Drop old tables
mysql_query('DROP TABLE PLAYERS');
mysql_query('DROP TABLE MATCHES');
mysql_query('DROP TABLE TOURNAMENT');
echo('Old tables dropped<br \>');

//Create new tables

// TOURNAMENT
mysql_query('CREATE TABLE TOURNAMENT(
tournamentID SMALLINT UNSIGNED PRIMARY KEY, 
)') or die(mysql_error());
echo('TOURNAMENT created...<br />');

// MATCHES
mysql_query('CREATE TABLE MATCHES(
    tournamentID SMALLINT UNSIGNED,
    matchID SMALLINT UNSIGNED,

    PRIMARY KEY (tournamentID, matchID),
    FOREIGN KEY (tournamentID) REFERENCES TOURNAMENT(tournamentID)
)') or die(mysql_error());
echo('MATCH created...<br />');

// PLAYERS
mysql_query('CREATE TABLE PLAYERS(
    tournamentID SMALLINT UNSIGNED,
    matchID SMALLINT UNSIGNED,
    playerID SMALLINT UNSIGNED,

    PRIMARY KEY (tournamentID, matchID),
    FOREIGN KEY (tournamentID) REFERENCES TOURNAMENT(tournamentID),
    FOREIGN KEY (matchID) REFERENCES MATCHES(matchID)
)') or die(mysql_error());
echo('PLAYERS created...<br />');

echo('Blank tables created');

mysql_close();

When I execute the PHP script I receive err 150, which I think has something to do with my primary keys/foreign key references in the PLAYERS table:

Old tables dropped
TOURNAMENT created...
MATCH created...
Can't create table 'stats.players' (errno: 150)

I have done some reading and looked at some previous questions but I don’t really understand the actual problem (the reason the error is occurring) in the first place. Clearly the design of my database is incorrect but I’m not sure how I should approach improving and fixing it.

Please 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-06-12T16:34:20+00:00Added an answer on June 12, 2026 at 4:34 pm

    Barring any problems with table definition that people are commenting on above, the reason you’re getting error 150 is because Players (obviously the table with the problem) can’t be created because it can’t use matchID as a foreign key. Why? Because you can only use foreign keys that are a key on the other table.

    PRIMARY KEY (one, two) does make a unique primary key from these two columns, but only one will be considered a key on its own.

    You can fix this easily by adding this to Matches:

    ...
    PRIMARY KEY (tournamentID, matchID),
    KEY (matchID),
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I don't have much knowledge about the IPv6 protocol, so sorry if the question
this is what i have right now Drawing an RSS feed into the php,
I'm trying to create an if statement in PHP that prevents a single post
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.