On Wed, May 19, 2010 at 10:59 AM, Shawn Green <shawn.l.gr...@oracle.com>wrote:

> Shawn Green wrote:
>
> AH! that's your mistake. You think that creating the FK will also create
> the column. That does not happen. You have to define the table completely
> before you can associate the columns on this table (the child table) with
> the correct column on the parent table (either Flights or Customers).
>
> You need to declare two more fields before you can link them through a
> Foreign Key relationship to a field on another table:
>
> CREATE TABLE PASSENGERS (
>  id int auto_increment
> , flights_id int not null
> , customer_id int not null
> ... other passenger table columns here ...
> , PRIMARY KEY (id)
> , FOREIGN KEY (flights_id) REFERENCES Flights(id)
> , FOREIGN KEY (customer_id) REFERENCES Customer(id)
> ) ENGINE=INNODB;
>
> Try it that way and see if it helps.
>
> Well, that was certainly one error, but there's another:

------------------------
LATEST FOREIGN KEY ERROR
------------------------
100519  8:46:10 Error in foreign key constraint of table
seaflight/Passengers:
foreign key (id) references Flights (flights_id), foreign key (id)
references Customers (customer_id), name varchar(40), weight tinyint(3))
engine=InnoDB:
Cannot resolve column name close to:
), foreign key (id) references Customers (customer_id), name varchar(40),
weight tinyint(3)) engine=InnoDB

Now, I've added the innodb engine to all tables and constraints on the id
columns of the foreign key tables. What else?
TIA,
V

Reply via email to