berita_ukm表
CREATE TABLE `berita_ukm` (
`id_berita` int(11) NOT NULL AUTO_INCREMENT,
`id_admin` int(11) DEFAULT NULL,
`judul_berita` varchar(45) DEFAULT NULL,
`content` varchar(225) DEFAULT NULL,
`tanggal` date DEFAULT NULL,
PRIMARY KEY (`id_berita`),
FOREIGN KEY (`id_admin`) REFERENCES `admin` (`id_admin`)
)
管理员表
CREATE TABLE `berita_ukm` (
`id_admin` int(11) NOT NULL AUTO_INCREMENT,
`name` int(11) DEFAULT NULL,
PRIMARY KEY (`id_admin`),
)
我发现这样的错误
Error Number: 1452
Cannot add or update a child row: a foreign key constraint fails
(`tugas_akhir`.`berita_ukm`, CONSTRAINT `berita_ukm_ibfk_1`
FOREIGN KEY (`id_admin`) REFERENCES `admin` (`id_admin`))
INSERT INTO `berita_ukm`
(`id_berita`, `tanggal`, `judul_berita`, `content`)
VALUES ('34', '3/25/2014', 'putri', 'nfdn')
请帮我做什么。谢谢
答案 0 :(得分:0)
我猜你错误地放置了插入中的col名称(" id_berita"代替" id_admin"),因为col" id_berita"是自动增量,您不需要在插入期间为该col提供值。
INSERT INTO `berita_ukm`
(`id_admin`, `tanggal`, `judul_berita`, `content`)
VALUES ('34', '3/25/2014', 'putri', 'nfdn')