大家好我想为一个得分项目制作一个游戏数据库,在SQL Fiddle上测试它并继续得到这个错误说PlayerID没有默认值,但是这是自动递增所以我不明白为什么?任何帮助将不胜感激。
CREATE TABLE tblPlayer (
PlayerID INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
UserName VARCHAR(50) NOT NULL,
Password VARCHAR(50) NOT NULL,
Email VARCHAR(100) NOT NULL,
HighScore INT (50),
AccountType BOOLEAN,
Status BOOLEAN,
Country VARCHAR (50)
);
CREATE TABLE tblGame (
GameID INT AUTO_INCREMENT PRIMARY KEY NOT NULL,
Timeleft DECIMAL NOT NULL
);
CREATE TABLE tblMap (
MapID INT AUTO_INCREMENT PRIMARY KEY NOT NULL,
GameID INT,
MineLocationXY VARCHAR(10),
OneLocationXY VARCHAR(10),
TwoLocationXY VARCHAR(10),
ThreeLocationXY VARCHAR(10),
FOREIGN KEY (GameID) REFERENCES tblGame (GameID)
);
CREATE TABLE tblPlayerGame (
PlayerID INT NOT NULL,
GameID INT NOT NULL,
PRIMARY KEY (PlayerID,GameID),
PlayerOneScore INT(50),
PlayerTwoScore INT(50),
FOREIGN KEY (PlayerID) REFERENCES tblPlayer (PlayerID),
FOREIGN KEY (GameID) REFERENCES tblGame (GameID)
);
CREATE TABLE tblPlayerClick (
PlayerID INT,
LocationX VARCHAR (10),
LocationY VARCHAR (10),
FOREIGN KEY (PlayerID) REFERENCES tblPlayer (PlayerID)
);
INSERT INTO tblPlayer (UserName,Password,Email,AccountType,Status,Country)
VALUES ('Geoff22','password2016','Geoff@Email.com',TRUE, TRUE, 'New Zealand'),
('Steve1','password','steve@Email.com',False, TRUE, 'USA')
;
INSERT INTO tblGame (TimeLeft)
VALUES (120), (120)
;
INSERT INTO tblMap (MineLocationXY,OneLocationXY,TwoLocationXY,ThreeLocationXY)
VALUES ('X2,Y3','X6,Y8','X9,Y1','X1,Y3')
;
INSERT INTO tblPlayerClick (LocationX,LocationY)
VALUES ('X1','Y2')
;
INSERT INTO tblPlayerGame (PlayerOneScore,PlayerTwoScore)
VALUES (22,19)
;
答案 0 :(得分:1)
对于此insert
:
INSERT INTO tblPlayerGame (PlayerOneScore,PlayerTwoScore)
VALUES (22,19);
您没有PlayerId
和GameId
的值。这些声明为NOT NULL
,没有默认值。
因此,您收到错误。