I'm having a bit of a problem creating foreign keys on a MySQL database.
The tables create and everything seems to be fine. But I just wanted to
test out adding a row to one of the child tables without having anything in
the parent table and it lets me insert the row, which it shouldn't
obviously. How do i create it so that the constraints work?
Thanks,
Bill
Here is my create table code:
CREATE TABLE tblPhotographs
(PhotoID INT NOT NULL AUTO_INCREMENT,
Photo BLOB,
PhotoDate DATETIME,
PRIMARY KEY(PhotoID))
TYPE=InnoDB;
CREATE TABLE tblPeople
(PhotoID INT NOT NULL,
PersonID INT NOT NULL AUTO_INCREMENT,
Person VARCHAR(50),
INDEX FK_PhotoID(PhotoID),
FOREIGN KEY(PhotoID) REFERENCES tblPhotographs(PhotoID),
PRIMARY KEY(PersonID))
TYPE=InnoDB;
CREATE TABLE tblPlaces
(PhotoID INT NOT NULL,
PlaceID INT NOT NULL AUTO_INCREMENT,
Place VARCHAR(50),
INDEX FK_PhotoID(PhotoID),
FOREIGN KEY(PhotoID) REFERENCES tblPhotographs(PhotoID),
PRIMARY KEY(PlaceID))
TYPE=InnoDB;
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.772 / Virus Database: 519 - Release Date: 10/1/2004