我设计了一个表,想要一个 ID 的整数自动增量列。 当然,我阅读了有关迁移参数的文档。
现在,我的代码如下所示:
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"
}
]
})
)
}
如您所见,id
未标记为 AI
。我做错了什么?
最佳答案
{
name: "id",
type: "int",
isPrimary: true,
isGenerated: true,
generationStrategy: "increment"
},
可用选项:
generationStrategy?: "uuid" | "increment" | "rowid" | "identity";
关于mysql - 如何在TypeORM迁移中创建自增整数字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72865932/