2
我想爲我的單任務創建一個數據庫,但我有在我的代碼,下同47線我的外鍵約束的麻煩;MYSQL出錯創建外國Constain
CONSTRAINT Sessions_Screen_ID_FK FOREIGN KEY (ScreenID) REFERENCES screen(ScreenID),
我收到的錯誤是
#1215 - 不能添加外鍵約束
,我似乎無法避開它。如果我刪除約束,但腳本運行正常。
我已經粘貼了以下完整的腳本: 謝謝你們的時間
Drop Database IF EXISTS AE2_ISYS114;
CREATE Database AE2_ISYS114;
CREATE TABLE AE2_ISYS114.branch(
BranchID char(2) NOT NULL,
BranchName varchar(20),
BranchSuburb varchar(15),
BranchPostCode char(4),
PRIMARY KEY (BranchID)
);
CREATE TABLE AE2_ISYS114.movie(
MovieID char(2) NOT NULL,
MovieName varchar(20),
MovieGenre varchar(20),
MovieClassification varchar(5),
PRIMARY KEY (MovieID)
);
CREATE TABLE AE2_ISYS114.screen(
ScreenID char(2) NOT NULL,
BranchID char(2),
ScreenCapacity int(3),
PRIMARY KEY (BranchID,ScreenID),
CONSTRAINT Screen_Branch_ID_fk FOREIGN KEY (BranchID) REFERENCES Branch(BranchID)
);
CREATE TABLE AE2_ISYS114.sessions(
SessionID char(4) NOT NULL,
BranchID char(2),
ScreenID char(2),
MovieID char(2),
SessionDate DATE,
SessionPrice Decimal(4,2),
PRIMARY KEY (SessionID),
CONSTRAINT Sessions_Branch_ID_fk FOREIGN KEY (BranchID) REFERENCES branch(BranchID),
CONSTRAINT Sessions_Screen_ID_FK FOREIGN KEY (ScreenID) REFERENCES screen(ScreenID),
CONSTRAINT Sessions_Movie_ID_fk FOREIGN KEY (MovieID) REFERENCES movie(MovieID)
);
OMG花了我兩小時去尋找只爲你指出的路上,我在屏幕的PKEY感謝搞砸了很多 –
這發生在每個開發人員的代碼,我自己肯定包括:) – Shadow