I Tabellen in MYSQL erstellt haben alsFehler beim Einfügen der recordsCannot hinzufügen oder ein Kind Zeile aktualisieren: ein Fremdschlüssel nicht
Autor Tabelle
CREATE TABLE `author` (
`AuthorId` varchar(25) NOT NULL,
`AuthorName` varchar(50) NOT NULL,
PRIMARY KEY (`AuthorId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
Bücher Tabelle
CREATE TABLE `books` (
`DocId` int(11) NOT NULL,
`ISBN` varchar(13) NOT NULL,
PRIMARY KEY (`DocId`),
KEY `DocId` (`DocId`),
CONSTRAINT `books_ibfk_1` FOREIGN KEY (`DocId`) REFERENCES `document`
(`DocId`)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1
folgt Dokumententabelle
CREATE TABLE `document` (
`DocId` int(11) NOT NULL,
`Title` varchar(50) NOT NULL,
`PublishDate` date DEFAULT NULL,
`AuthorId` varchar(10) DEFAULT NULL,
`DocType` varchar(10) DEFAULT NULL,
PRIMARY KEY (`DocId`),
KEY `AuthorId` (`AuthorId`),
CONSTRAINT `document_ibfk_3` FOREIGN KEY (`AuthorId`) REFERENCES `author`
(`AuthorId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
habe ich einen Server für meine PHP-Website auf XAMPP und mysql bin mit aber wenn ich versuche, die Werte in Document Tabelle einfügen ich
error while inserting the recordsCannot add or update a child row: a foreign
key constraint fails (`librarydb`.`document`, CONSTRAINT `document_ibfk_3`
FOREIGN KEY (`AuthorId`) REFERENCES `author` (`AuthorId`))
Wie kann ich dieses Problem beheben?
die Längen/NULL oderNOT NULL missmatch zwischen 'author.AuthorId' und' document.AuthorId' – Jeff
und während Sie dabei sind: Fragen Sie sich, ob 'AuthorId' wirklich eine Zeichenfolge sein muss. – Jeff