Skip to content

Can't create UNIQUE constraints with column name ofgroup in sqlite #4407

Closed

Description

@zuohaocheng

I've created a table with a column, named group, and there's a UNIQUE constraint on it. It works on postgres, but will fail on sqlite. The SQL statement is

CREATE TABLE IF NOT EXISTS `Requests` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `group` INTEGER NOT NULL REFERENCES `Groups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, `license` INTEGER NOT NULL REFERENCES `Licenses` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, UNIQUE (group, license));

However the correct SQL should be as below, which needs column names in UNIQUE to be quoted.

CREATE TABLE IF NOT EXISTS `Requests` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `group` INTEGER NOT NULL REFERENCES `Groups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, `license` INTEGER NOT NULL REFERENCES `Licenses` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, UNIQUE (`group`, `license`));

May you help to fix the issue, thank you.

Table definition:

sequelize.define('Request', {
    group: {
      type: Sequelize.INTEGER,
      allowNull: false,
      unique: 'uGroupLicense'
    },
    license: {
      type: Sequelize.INTEGER,
      allowNull: false,
      unique: 'uGroupLicense'
    }
  }

Activity

  1. added
    type: bug
    on Aug 31, 2015
  2. added 2 commits that reference this issue on Feb 19, 2017
    033524e
    b002ac2
  3. added a commit that references this issue on Feb 22, 2017
    6ca925b
  4. added a commit that references this issue on Apr 25, 2017
    8de7543
  5. added a commit that references this issue on Nov 13, 2017
    2c2eca3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions