Skip to content

CHECK constraint failed with SQLite and simple-enum array #6326

Closed

Description

@khannurien

Issue type:

[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[x] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

Hi,

When trying to use a simple-enum array as a column type with SQLite 3.22.0 and TypeORM 0.2.25, I get an SQL_CONSTRAINT CHECK error:

 QueryFailedError: SQLITE_CONSTRAINT: CHECK constraint failed: user
    at new QueryFailedError (/path/node_modules/typeorm/error/QueryFailedError.js:11:28)
    at Statement.handler (/path/node_modules/typeorm/driver/sqlite/SqliteQueryRunner.js:48:38) {
  errno: 19,
  code: 'SQLITE_CONSTRAINT',
  query: 'INSERT INTO "user"("id", "username", "password", "email", "roles", "support") VALUES (NULL, ?, ?, ?, ?, ?)',
  parameters: [
    'admin',
    'xxx',
    '[email protected]',
    '0,1',
    1
  ]
}

The enum column in my entity:

    @Column({
        type: 'simple-enum',
        enum: UserRole,
        array: true,
        nullable: false
      })
    roles: UserRole[];

The UserRole type:

export enum UserRole {
    ADMIN,
    DEVELOPER,
    USER,
}

The code I use to instantiate an user:

this.create({
            username: 'admin',
            password: 'xxx',
            email: '[email protected]',
            roles: [UserRole.ADMIN, UserRole.DEVELOPER],
            support: true
        })

Did I miss something?

Note: if I put one value only in the roles array during instantiation, the new user is indeed created.

Thanks!

Activity

  1. imnotjames commented on Oct 12, 2020

    @imnotjames
    Contributor

    What is the DDL of your table?

    Can you create a reproducible example as a repo or as a test in a PR that we can use for verifying this erroneous behavior?

  2. imnotjames commented on Jun 25, 2021

    @imnotjames
    Contributor

    When opening an issue, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This boils down to ensuring your code that reproduces the problem follows the following guidelines:

    • Minimal – Use as little code as possible that still produces the same problem
    • Complete – Provide all parts someone else needs to reproduce your problem in the question itself
    • Reproducible – Test the code you're about to provide to make sure it reproduces the problem

    Minimal

    The more code there is to go through, the less likely people can find your problem. Streamline your example in one of two ways:

    1. Restart from scratch. Create a new program, adding in only what is needed to see the problem. Use simple, descriptive names for functions and variables – don’t copy the names you’re using in your existing code.
    2. Divide and conquer. If you’re not sure what the source of the problem is, start removing code a bit at a time until the problem disappears – then add the last part back.

    Don't sacrifice clarity for brevity when creating a minimal example. Use consistent naming and indentation, and include code comments if needed. Use your code editor’s shortcut for formatting code.

    Don't include any passwords or credentials that must be kept secret.

    Complete

    Make sure all information necessary to reproduce the problem is included in the issue itself.

    If the problem requires some code as well as some XML-based configuration, include code for both. The problem might not be in the code that you think it is in.

    Use individual code blocks for each file or snippet you include. Provide a description for the purpose of each block.

    DO NOT use images of code. Copy the actual text from your code editor, paste it into the issus, then format it as code. This helps others more easily read and test your code.

    Reproducible

    To help you solve your problem, others will need to verify that it exists.

    Describe the problem. "It doesn't work" isn't descriptive enough to help people understand your problem. Instead, tell other readers what the expected behavior should be. Tell other readers what the exact wording of the error message is, and which line of code is producing it. Use a brief but descriptive summary of your problem as the title of your question.

    Eliminate any issues that aren't relevant to the problem. If your question isn’t about a compiler error, ensure that there are no compile-time errors.

    Double-check that your example reproduces the problem! If you inadvertently fixed the problem while composing the example but didn't test it again, you'd want to know that before asking someone else to help.

  3. TechQuery commented on Oct 20, 2025

    @TechQuery

    @michaelbromley I think this issue should reopen and be fixed in the new age of TypeORM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions