|
Subject:
|
Try this and tell me whats the problem?
|
|
Posted By:
|
nsakic
|
Post Date:
|
1/8/2004 8:56:32 AM
|
CREATE TABLE publisher ( publisherID int(11) NOT NULL auto_increment, publisherName varchar(32) NOT NULL default '', PRIMARY KEY(publisherID) ) TYPE=INNODB;
-- -- Table structure for table 'authors' -- CREATE TABLE authors ( authorID int(11) NOT NULL auto_increment, FirstName varchar(20) NOT NULL default '', LastName varchar(20) NOT NULL default '', PRIMARY KEY (authorID) ) TYPE=INNODB;
-- -- Table structure for table 'titles' -- CREATE TABLE titles ( isbn varchar(20) NOT NULL, title varchar(64) NOT NULL, copyright varchar(20) NOT NULL, publisherID int(11) NOT NULL, comments varchar(128) NOT NULL default '', publishers_publisherID INT, PRIMARY KEY(isbn), INDEX (publishers_publisherID), FOREIGN KEY(publishers_publisherID) REFERENCES publisher (publisherID) ) TYPE=INNODB;
-- -- Table structure for table 'authorsISBN' -- CREATE TABLE authorISBN ( authorID int(11) NOT NULL, isbn varchar(20) NOT NULL, authors_authorID INT NOT NULL, titles_isbn varchar(20) NOT NULL, INDEX (authors_authorID), FOREIGN KEY(authors_authorID) REFERENCES authors (authorID), INDEX (titles_isbn), FOREIGN KEY(titles_isbn) REFERENCES titles(isbn) ) TYPE=INNODB;
# example insert statements
INSERT INTO authors values (1,"H.M.","Deitel");
INSERT INTO titles values ("0130895601","Advanced Java 2 Platform How to Program",2001,1,"X",NULL);
INSERT INTO publisher values (1, "Printice Hall");
I am not able to use any insert statements with my authorISBN table. All the about insert statemetns works fine, but when i try to insert into authorISBN, i get an error:
Error: 1216: Can not add or update a child row: a foreign key constraint failure.
Can someone please create a database and add the tables and help me out here. MySQL manual does not explain this well. Thanx in advance.
-Nikolas
|
|
Reply By:
|
nsakic
|
Reply Date:
|
1/8/2004 5:17:50 PM
|
Nevermind, i fixed the problem. In authorISBN table, i just removed 'NOT NULL' exp from the Index declaration.
Nikolas
|
|