gpt4 book ai didi

mysql - 我无法添加外键约束? mysql

转载 作者:行者123 更新时间:2023-11-29 22:47:55 25 4
gpt4 key购买 nike

我无法创建第二个表,因为 Mysql 打印出错误代码 12 15 的消息,但我不明白脚本中的问题是什么。

我有两张 table :

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;

关于mysql - 我无法添加外键约束? mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29013142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com