Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unique ignored on single-column index without explicit name #195

Closed
enaeseth opened this issue Jan 13, 2017 · 1 comment
Closed

unique ignored on single-column index without explicit name #195

enaeseth opened this issue Jan 13, 2017 · 1 comment
Labels

Comments

@enaeseth
Copy link

(using TypeORM v0.0.6 with SQLite engine)

Adding @Index({unique: true}) to a column creates a non-unique index. Adding an explicit index name to the Index call fixes the issue:

without index name:

@Table()
export class User {
    @PrimaryGeneratedColumn()
    id: number

    @Column({length: 50})
    @Index({unique: true})
    username: string
}

generates schema:

CREATE TABLE "user" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "username" character varying(50) NOT NULL);
CREATE INDEX "ind_300353b186d0848c390a64e70f1" ON "user"("username");

with index name:

@Table()
export class User {
    @PrimaryGeneratedColumn()
    id: number

    @Column({length: 50})
    @Index('user_username', {unique: true})
    username: string
}

generates schema:

CREATE TABLE "user" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "username" character varying(50) NOT NULL);
CREATE UNIQUE INDEX "user_username" ON "user"("username");
@pleerock
Copy link
Member

that was a bug. Fixed and released in 0.0.7-alpha.14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants