playground icon indicating copy to clipboard operation
playground copied to clipboard

autoIncrementIncrement not work in postgres

Open sasakiyori opened this issue 6 months ago • 0 comments

Explain your user case and expected results

type Book struct {
	BookID int    `gorm:"column:book_id;autoIncrement:true;autoIncrementIncrement:10"`
	Name   string `gorm:"column:name;type:varchar(255)"`
}
GORM_DIALECT=postgres go test

Whether autoIncrementIncrement is set or not, the increment step is always 1.

2024/08/20 16:54:05 testing postgres...

2024/08/20 16:54:05 /Users/sasakiyori/go/pkg/mod/gorm.io/driver/[email protected]/migrator.go:186
[0.348ms] [rows:1] SELECT count(*) FROM information_schema.tables WHERE table_schema = CURRENT_SCHEMA() AND table_name = 'books' AND table_type = 'BASE TABLE'

2024/08/20 16:54:05 /Users/sasakiyori/go/pkg/mod/gorm.io/driver/[email protected]/migrator.go:157
[1.049ms] [rows:0] CREATE TABLE "books" ("book_id" bigserial,"name" varchar(255))

2024/08/20 16:54:05 /Users/sasakiyori/gitcode/playground/main_test.go:23
[1.291ms] [rows:1] select increment from information_schema.sequences where sequence_name = 'books_book_id_seq'
--- FAIL: TestGORM (0.00s)
    main_test.go:30: auto increment should be 10, but get 1
FAIL
exit status 1
FAIL    gorm.io/playground      0.688s

sasakiyori avatar Aug 20 '24 08:08 sasakiyori