我有一个终生都无法解决的问题。我一直在使用XAMPP在windows上用PHP/MySQL创建一个应用程序,但现在我正尝试在基于Linux的LAMP服务器上测试它,在尝试创建具有外键约束的表时出现以下错误:
“3-photoprojecttem表创建:无法添加外键约束”
当我在Windows中的XAMPP上运行代码时,它运行得很好,但在Linux中不行。以下是我要创建的表:
CREATE TABLE IF NOT EXISTS generalSecurity(
id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(100) UNIQUE NOT NULL,
password VARCHAR(100) NOT NULL,
firstname VARCHAR(100) NOT NULL,
secondname VARCHAR(100) NOT NULL,
accessLevel ENUM('admin', 'contributer', 'subscriber') NOT NULL,
Email VARCHAR (200) UNIQUE NOT NULL
) ENGINE=INNODB;
CREATE TABLE IF NOT EXISTS generalSiteInfo (
id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
siteName VARCHAR(100) NOT NULL,
siteOwnerID INT(10) UNSIGNED NOT NULL,
INDEX par_id4(siteOwnerID),
FOREIGN KEY(siteOwnerID)
REFERENCES generalSecurity(id)
ON DELETE CASCADE,
siteEmail VARCHAR(100) NOT NULL,
siteAbout VARCHAR(9999) NOT NULL,
currentTheme VARCHAR(1000) NOT NULL,
siteCreateDate TIMESTAMP
DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP
) ENGINE=INNODB;
CREATE TABLE IF NOT EXISTS Project (
id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
projectAuthorID INT(10) UNSIGNED NOT NULL,
INDEX par_id(projectAuthorID),
FOREIGN KEY(projectAuthorID)
REFERENCES generalSecurity(id)
ON DELETE CASCADE,
projectName VARCHAR(100) NOT NULL,
projectBlurb VARCHAR(5000) NULL,
projectTheme VARCHAR(100) NOT NULL,
projectDate TIMESTAMP
) ENGINE=INNODB;
CREATE TABLE IF NOT EXISTS ProjectItem (
id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
authorID INT(10) UNSIGNED NOT NULL,
INDEX par_id2(authorID),
FOREIGN KEY(authorID)
REFERENCES generalSecurity(id)
ON DELETE CASCADE,
projectID INT(10) UNSIGNED NOT NULL,
INDEX par_id3(projectID),
FOREIGN KEY(projectID)
REFERENCES project(id)
ON DELETE CASCADE,
itemType ENUM('image', 'text') NOT NULL,
photoFileName VARCHAR(100) NULL,
itemName VARCHAR(1000) NOT NULL,
entry VARCHAR(5000) NULL,
photoMeta VARCHAR(5000) NOT NULL,
date TIMESTAMP,
deleted BOOLEAN NOT NULL
) ENGINE=INNODB;
尝试创建表“projecttem”时失败。你们能看到我遗漏了什么吗?
我真的很感激你能给我的帮助
---编辑---
当我把线移开
INDEX par_id3(projectID),
FOREIGN KEY(projectID)
REFERENCES project(id)
ON DELETE CASCADE,
但我看不出这段关系有什么明显的问题
最佳答案
问题是,在Linux中,MYSQL显然是区分大小写的,而在Windows中则不是。当表“project”被称为“project”时,我试图为它创建一个关系
关于php - MySQL外键约束在Linux Server上失败,但在Windows XAMPP上工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39348013/