List:General Discussion« Previous MessageNext Message »
From:Victor Subervi Date:May 18 2010 1:44pm
Subject:Foreign Key Problem
View as plain text  
Hi;
mysql> create table if not exists Passengers (id int unsigned auto_increment
primary key, foreign key (id) references Flights (flights_id), foreign key
(id) references Customers (customer_id), name varchar(40), weight
tinyint(3));
Query OK, 0 rows affected (0.00 sec)

mysql> select c.first_name, c.middle_name, c.last_name, c.suffix,
c.discount, p.flights_id from Customers c join Passengers p on
c.id=p.customer_id
where flights_id=1;
ERROR 1054 (42S22): Unknown column 'p.flights_id' in 'field list'
mysql> describe Passengers;
+--------+------------------+------+-----+---------+----------------+
| Field  | Type             | Null | Key | Default | Extra          |
+--------+------------------+------+-----+---------+----------------+
| id     | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name   | varchar(40)      | YES  |     | NULL    |                |
| weight | tinyint(3)       | YES  |     | NULL    |                |
+--------+------------------+------+-----+---------+----------------+
3 rows in set (0.01 sec)

So, why didn't the foreign key get created? It exists as a primary key in
Customers. Please advise.
TIA,
Victor

Thread
Foreign Key ProblemVictor Subervi18 May
  • Re: Foreign Key ProblemJohan De Meersman18 May
    • Re: Foreign Key ProblemVictor Subervi18 May
      • Re: Foreign Key ProblemJohan De Meersman18 May
        • Re: Foreign Key ProblemShawn Green18 May
          • Re: Foreign Key ProblemVictor Subervi18 May
            • Re: Foreign Key ProblemShawn Green18 May
              • Re: Foreign Key ProblemVictor Subervi19 May
                • Re: Foreign Key ProblemShawn Green19 May
                  • Re: Foreign Key ProblemVictor Subervi19 May
                    • Re: Foreign Key ProblemShawn Green19 May
                      • Re: Foreign Key ProblemVictor Subervi20 May
                        • Re: Foreign Key ProblemVictor Subervi22 May