I want to create two table AdminSessions
and UserSessions
to store the client session data. Both of them have a pk named sessionKey
with the properties of PK
, NN
, UQ
. When I try to do a forward engineering, I encounter Can't write; duplicate key in table 'UserSessions'
. After reading this solution, I try to change the name of the pks to sessionKeya
and sessionKeyb
but it does not work.
How to solve this error?
Error Message
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