我想创建两个表AdminSessions
和UserSessions
来存储客户端会话数据。它们都有一个名为sessionKey
的pk,其属性为PK
,NN
,UQ
。当我尝试进行前向工程时,遇到Can't write; duplicate key in table 'UserSessions'
。阅读this solution后,我尝试将pks的名称更改为sessionKeya
和sessionKeyb
但不起作用。
如何解决此错误?
错误消息
ERROR: Error 1022: Can't write; duplicate key in table 'UserSessions'
SQL
CREATE TABLE IF NOT EXISTS `CodeSpace`.`UserSessions` (
`sessionKey` VARCHAR(128) NOT NULL,
`userId` INT UNSIGNED NOT NULL,
`lastAccessTime` DATETIME NULL,
`ip` VARCHAR(45) NULL,
`expiryTime` DATETIME NULL,
PRIMARY KEY (`sessionKey`),
UNIQUE INDEX `userId_UNIQUE` (`userId` ASC),
UNIQUE INDEX `id_UNIQUE` (`sessionKey` ASC),
CONSTRAINT `fk_UserSession_1`
FOREIGN KEY (`userId`)
REFERENCES `CodeSpace`.`Users` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB