MySQL外键约束在Linux服务器上失败,但适用于Windows XAMPP

时间:2016-09-06 11:30:26

标签: php mysql linux windows lamp

我有一个问题,我无法理解我的生活。我一直在使用XAMPP在Windows上用PHP / MySQL创建应用程序,但现在我试图在基于Linux的LAMP服务器上测试它,并且在尝试创建具有外键约束的表时出现以下错误:

“3 - photoProjectItem表创建:无法添加外键约束”

当我在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;

尝试创建表“ProjectItem”时失败。你们能看到我错过的任何东西吗?

我非常感谢能给予的任何帮助

--- ---编辑

当我删除行

时它会起作用
           INDEX par_id3(projectID),
        FOREIGN KEY(projectID)
            REFERENCES project(id)
            ON DELETE CASCADE,

但是我看不出任何明显的关系问题

1 个答案:

答案 0 :(得分:1)

问题在于Linux中的MYSQL是区分大小写的,而在Windows中它看起来并不像。当它被称为“项目”时,我试图为表“项目”创建一个关系