不能写;表格中的重复键' UserSessions'甚至pk名称也改变了

时间:2016-07-24 08:25:06

标签: mysql

我想创建两个表AdminSessionsUserSessions来存储客户端会话数据。它们都有一个名为sessionKey的pk,其属性为PKNNUQ。当我尝试进行前向工程时,遇到Can't write; duplicate key in table 'UserSessions'。阅读this solution后,我尝试将pks的名称更改为sessionKeyasessionKeyb但不起作用。

如何解决此错误?

错误消息

ERROR: Error 1022: Can't write; duplicate key in table 'UserSessions'

enter image description here enter image description here

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

0 个答案:

没有答案