你能帮我搞清楚吗
当我尝试创建表dvdTitle时,我遇到错误
错误代码:1005
无法创建表'netflixclone.dvdtitle'(错误号:150)
这是代码。不确定出了什么问题
CREATE TABLE IF NOT EXISTS `netflixclone`.`person` (
`personID` INT NOT NULL ,
`personFirstName` VARCHAR(50) NULL ,
`personLastName` VARCHAR(50) NULL ,
`actor` TINYINT(1) NULL ,
`producer` TINYINT(1) NULL ,
`director` TINYINT(1) NULL ,
PRIMARY KEY (`personID`) );
CREATE TABLE IF NOT EXISTS `netflixclone`.`dvdTitle` (
`dvdID` INT NOT NULL AUTO_INCREMENT ,
`dvdMPPARating` VARCHAR(45) NULL ,
`dvdProducer` INT NOT NULL,
`dvdDirector` INT NOT NULL,
PRIMARY KEY (`dvdID`) ,
CONSTRAINT `personID`
FOREIGN KEY (`dvdProducer` , `dvdDirector` )
REFERENCES `netflixclone`.`person` (`personID` , `personID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION);
答案 0 :(得分:0)
尝试制作' netflixclone.dvdtitle'表默认字符集为utf8。
CREATE TABLE IF NOT EXISTS `netflixclone`.`dvdTitle` (
`dvdID` INT NOT NULL AUTO_INCREMENT ,
`dvdMPPARating` VARCHAR(45) NULL ,
`dvdProducer` INT NOT NULL,
`dvdDirector` INT NOT NULL,
PRIMARY KEY (`dvdID`) ,
CONSTRAINT `personID`
FOREIGN KEY (`dvdProducer` , `dvdDirector` )
REFERENCES `netflixclone`.`person` (`personID` , `personID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION) CHARSET=utf8;
答案 1 :(得分:0)
你的约束很奇怪。我想你想要两个约束。
CREATE TABLE IF NOT EXISTS `netflixclone`.`dvdTitle` (
`dvdID` INT NOT NULL AUTO_INCREMENT ,
`dvdMPPARating` VARCHAR(45) NULL ,
`dvdProducer` INT NOT NULL,
`dvdDirector` INT NOT NULL,
PRIMARY KEY (`dvdID`) ,
CONSTRAINT FOREIGN KEY (`dvdProducer`) REFERENCES `netflixclone`.`person`
ON DELETE NO ACTION ON UPDATE NO ACTION),
CONSTRAINT FOREIGN KEY (`dvdDirector`) REFERENCES `netflixclone`.`person`
ON DELETE NO ACTION ON UPDATE NO ACTION)
);
答案 2 :(得分:0)
FOREIGN KEY (
你可以试试这个dvdProducer
)
REFERENCES netflixclone
.person
(personID
)