我创建了以下脚本来设置我的 MySQL 数据库:
CREATE DATABASE IF NOT EXISTS magicc_hat;
USE magicc_hat;
CREATE TABLE people (
personID INT NOT NULL AUTO_INCREMENT,
firstName VARCHAR(45) NOT NULL,
lastName VARCHAR(45),
archived BOOL NOT NULL DEFAULT '0',
PRIMARY KEY (personID)
);
CREATE TABLE categories (
categoryID INT NOT NULL AUTO_INCREMENT,
categoryName VARCHAR(45) NOT NULL,
description TEXT,
archived BOOL NOT NULL DEFAULT '0',
PRIMARY KEY (categoryID)
);
CREATE TABLE homes (
homeID INT NOT NULL AUTO_INCREMENT,
homeName VARCHAR(45) NOT NULL,
notes TEXT,
archived BOOL NOT NULL DEFAULT '0',
PRIMARY KEY (homeID)
};
CREATE TABLE items (
itemID INT NOT NULL AUTO_INCREMENT,
itemName VARCHAR(100) NOT NULL,
identifier VARCHAR(100),
quantity INT NOT NULL,
categoryID INT NOT NULL,
homeID INT NOT NULL,
itemStatus ENUM('normal', 'broken', 'missing') NOT NULL DEFAULT 'normal',
description TEXT,
image VARCHAR(45),
notes TEXT,
archived BOOL NOT NULL DEFAULT '0',
PRIMARY KEY (itemID),
FOREIGN KEY (categoryID) REFERENCES categories(categoryID),
FOREIGN KEY (homeID) REFERENCES homes(homeID)
};
CREATE TABLE projects (
projectID INT NOT NULL AUTO_INCREMENT,
projectName VARCHAR(45) NOT NULL,
description TEXT,
archived BOOL NOT NULL DEFAULT '0',
PRIMARY KEY (projectID)
);
CREATE TABLE checkouts (
checkoutID INT NOT NULL AUTO_INCREMENT,
itemID INT NOT NULL,
personID INT NOT NULL,
projectID INT,
quantity INT NOT NULL,
outDateTime DATETIME,
inDateTime DATETIME,
outNotes TEXT,
inNotes TEXT,
checkedIn BOOL,
archived BOOL NOT NULL DEFAULT '0',
PRIMARY KEY (checkoutID),
FOREIGN KEY (itemID) REFERENCES items(itemID),
FOREIGN KEY (personID) REFERENCES people(personID),
FOREIGN KEY (projectID) REFERENCES projects(projectID)
);
但是,当我运行此脚本时,我收到以下错误消息:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '}' at line 8
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '}' at line 17
ERROR 1215 (HY000): Cannot add foreign key constraint
我怀疑这与使用 bool 数据类型有关,因为这是第 8 行和第 17 行发生的事情;但是我无法在网上找到任何解决此问题的方法。有人能够看到可能导致问题的原因吗?我在本地 Windows 机器上运行 MySQL 5.6.11。
谢谢!