我无法创建第二个表,因为Mysql打印出错误代码为12 15的消息,但是我不明白脚本中的问题是什么。
我有两个表:
CREATE TABLE IF NOT EXISTS `tsmdb_centralized`.`customer_accounts` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`customerAccountName` VARCHAR(50) NOT NULL,
`customerAccountUser` VARCHAR(50) NOT NULL,
`customerAccountServer` VARCHAR(45) NOT NULL,
`password` VARCHAR(20) NOT NULL,
`status` TINYINT(50) NOT NULL,
PRIMARY KEY (`id`, `customerAccountServer`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `tsmdb_centralized`.`bugs_etl`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `tsmdb_centralized`.`bugs_etl` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`bug_title` VARCHAR(45) NOT NULL,
`bug_description` VARCHAR(500) NULL,
`customerAccountServer` VARCHAR(45) NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_bugs_etl_customer_accounts_idx` (`customerAccountServer` ASC),
CONSTRAINT `fk_bugs_etl_customer_accounts`
FOREIGN KEY (`customerAccountServer`)
REFERENCES `tsmdb_centralized`.`customer_accounts` (`customerAccountServer`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
我发现了错误,您想获取一个外键'CustomerAccountServer'varchar(50),并且只能有一个引用唯一字段的外键。修改您的customer_accounts表,以便customeraccountServer字段是唯一的。
CREATE TABLE IF NOT EXISTS `tsmdb_centralized`.`customer_accounts` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`customerAccountName` VARCHAR(50) NOT NULL,
`customerAccountUser` VARCHAR(50) NOT NULL,
`customerAccountServer` VARCHAR(45) NOT NULL,
`password` VARCHAR(20) NOT NULL,
`status` TINYINT(50) NOT NULL,
PRIMARY KEY (`id`, `customerAccountServer`),
UNIQUE KEY `customerAccountServer_UNIQUE` (`customerAccountServer`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句