gorm icon indicating copy to clipboard operation
gorm copied to clipboard

How to use autoIncrement and autoIncrementIncrement?

Open mrunhap opened this issue 2 years ago • 4 comments

Your Question

autoIncrement 和 autoIncrementIncrement 好像没有效果.

autoIncrement and autoIncrementIncrement seems has no effect.

The document you expected this should be explained

https://gorm.io/docs/models.html#Fields-Tags

Expected answer

I want make two table's auto increment ID don't duplicate, one is auto increment start by 1, and offset is 2, another table start by 2, offset is 2. So that table 1's ID is 1,3,5,7..... And table 2's ID looks like 2,4,6,8....

I try this but it not work

type TestTableOne struct {
    ID int `gorm:"autoIncrement:1;autoIncrementIncrement:2"`
}

type TestTableTwo struct {
    ID int `gorm:"autoIncrement:2;autoIncrementIncrement:2"`
}

mrunhap avatar Apr 27 '22 07:04 mrunhap

same issue. tried every combination of autoIncrement and autoIncrementIncrement. nothing seems to work to define the offset for the auto incrementing column

Postgres DB

kashif9798 avatar May 13 '22 13:05 kashif9798

@jinzhu

mrunhap avatar Jun 02 '22 06:06 mrunhap

这俩值是在migrate的时候使用的。。。 目前迁移的时候,也有bug,根本就不生效。。。 哎,自己动手丰衣足食吧~

wclssdn avatar Jun 23 '22 10:06 wclssdn

我本地尝试改了下,可以工作,参考:https://github.com/go-gorm/gorm/pull/5452

wclssdn avatar Jun 23 '22 10:06 wclssdn

already solve

li-jin-gou avatar Dec 09 '22 16:12 li-jin-gou