MySQL改变了表名的情况

时间:2014-03-17 18:31:26

标签: mysql mysql-workbench

当我使用MySQL Workbench将我的模型转发到工作簿时,它会创建一个脚本文件,其中包含引号中表格的名称。表名都是大小写混合的,但是当脚本运行时,只有第一个表是用大小写创建的,其余的只是用小写创建的。 20+中的前两个表格如下所示:

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';

CREATE SCHEMA IF NOT EXISTS `CCBPlus` ;
USE `CCBPlus` ;

-- -----------------------------------------------------
-- Table `CCBPlus`.`Contacts`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `CCBPlus`.`Contacts` (
  `ContactId` INT(11) NOT NULL,
  `ContactType` BIT(3) NOT NULL COMMENT 'Contact Type: 0=Individual, 1=Corporate,   2=Family, 3=Branch, 4=Department, 5=Group, 6=Fund/GIC/Bank company',
  `DisplayName` VARCHAR(80) NOT NULL,
  `SearchName` VARCHAR(80) NOT NULL,
  `Prefix` VARCHAR(15) NULL DEFAULT NULL,
  `LastName` VARCHAR(50) NULL,
  `Initials` VARCHAR(10) NULL DEFAULT NULL,
  `FirstName` VARCHAR(40) NULL DEFAULT NULL,
  `Suffix` VARCHAR(10) NULL DEFAULT NULL,
  `OrganizationName` VARCHAR(50) NULL DEFAULT NULL,
  `InCareOf` VARCHAR(80) NULL COMMENT 'If mail is to be sent with the line \"In care of  [X]\"',
  `Birthdate` DATETIME NULL DEFAULT NULL,
  `Deceased` DATETIME NULL,
  `SocialSecurityNumber` VARCHAR(20) NULL DEFAULT NULL,
  `Gender` BIT(1) NULL DEFAULT 0 COMMENT '0=Male,1=Female',
  `CulturePreference` VARCHAR(10) NULL DEFAULT 'EN-CA' COMMENT 'Global Culture variable, e.g. EN-CA or FR-CA or other.',
  `LastMeeting` DATETIME NULL DEFAULT NULL,
  `Hobbies` VARCHAR(100) NULL,
  `Inactive` TINYINT(1) NOT NULL DEFAULT False,
  `Created` DATETIME NOT NULL,
  `LastModified` DATETIME NOT NULL,
  PRIMARY KEY (`ContactId`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COMMENT = 'Stores contact and optionally personal information for other' /* comment truncated */ /* entities. */;

-- -----------------------------------------------------
-- Table `CCBPlus`.`Branches`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `CCBPlus`.`Branches` (
  `BranchID` INT NOT NULL AUTO_INCREMENT,
  `Name` VARCHAR(50) NOT NULL COMMENT 'Unique name of this branch.',
  `Code` VARCHAR(4) NOT NULL COMMENT 'Internal code for the branch number.',
  `BranchContactId` INT NULL COMMENT 'Provides the address and contact information for  the branch.',
  `BranchManagerID` INT NULL COMMENT 'ID of the agent that manages this branch.',
  `PartnerDirectOfficerID` INT NULL COMMENT 'ID of the partner that is responsible for  this branch.',
  `HeadOffice` TINYINT(1) NOT NULL DEFAULT False COMMENT 'True if this branch is the head office.',
  `VirtualBranch` TINYINT(1) NOT NULL DEFAULT False COMMENT 'Indicates that this branch  is used only for organizational purposes and is not a real branch.',
  `Inactive` TINYINT(1) NOT NULL DEFAULT False COMMENT 'True if this branch is no longer in use.',
  PRIMARY KEY (`BranchID`),
  CONSTRAINT `fk_Branch_ContactInfo`
    FOREIGN KEY (`BranchContactId`)
    REFERENCES `CCBPlus`.`Contacts` (`ContactId`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Branch_Manager`
    FOREIGN KEY (`BranchManagerID`)
    REFERENCES `CCBPlus`.`Agents` (`AgentID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Branch_PartnerDirectOfficer`
    FOREIGN KEY (`PartnerDirectOfficerID`)
    REFERENCES `CCBPlus`.`Agents` (`AgentID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
COMMENT = 'Can represent a physical branch office, head office or a vir' /* comment truncated */ /*tual branch for organizational purposes.*/;
...

当MySQL Workbench执行脚本时,一切都正常运行,但我最终得到一个表正确的表:'Contacts',以及其他只有小写的表:'branches'。

我有lower_case_table_names = 2.

我正在使用MySQL 5.1.72社区版运行MySQL Workbench版本6.0.9.11421 build 1170。

任何帮助或建议都将不胜感激。

谢谢,Neil

2 个答案:

答案 0 :(得分:1)

在向MySQL开发人员报告此错误后,他们回来时建议我将小写表名设置为零:

lower_case_table_names = 0

这解决了在Windows 7开发平台上运行时的问题。顺便说一句,手动重命名表完全搞砸了我的MySQL Workbench Model和我的Entity Framework模型。我不得不使用数据库重新同步实体框架模型,并再次手动将数据存储表与我的实体匹配,然后手动删除创建的额外表和连接。

答案 1 :(得分:-2)

CREATE TABLE IF NOT EXISTS `CCBPlus`.`Branches` (
.....
REFERENCES `CCBPlus`.`Agents` (`AgentID`) <--- the table `Agents`
                                           --not created before creating this table.
.....