Home > Net >  How to create autoincrement integer field in TypeORM migration?
How to create autoincrement integer field in TypeORM migration?

Time:07-06

I design a table and want an integer autoincrement column for an ID. For sure, I read the docs about isGenerated param for migrations.

Now, my code looks like this:

public async up(queryRunner: QueryRunner): Promise<void> {

        await queryRunner.createTable(
            new Table({
                name: tableName,

                columns: [
                    {
                        name: "id",
                        type: "int",
                        isGenerated: true,
                        isPrimary: true,
                    },
                    {
                        name: "seller_id",
                        type: "int"
                    }
                ]
            })
      )
}

But as a result, I got: WorkBench

As you can see, id is not flagged as AI. What I'm doing wrong?

CodePudding user response:

{
    name: "id",
    type: "int",
    isPrimary: true,
    isGenerated: true,
    generationStrategy: "increment"
 },

available options:

generationStrategy?: "uuid" | "increment" | "rowid" | "identity";

   
  • Related