postgres
postgres copied to clipboard
Missing autoIncrement in postgres table schema output
This is my table schema
CREATE TABLE public.log_usage (
log_id bigint NOT NULL
);
ALTER TABLE public.log_usage ALTER COLUMN log_id ADD GENERATED BY DEFAULT AS IDENTITY (
SEQUENCE NAME public.log_usage_log_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);
ALTER TABLE ONLY public.log_usage
ADD CONSTRAINT pk_log_usage PRIMARY KEY (log_id);
And this is the generator output:
type LogUsage struct {
LogID int64 `gorm:"column:log_id;type:int8;primaryKey" json:"log_id"`
}
Expected:
type LogUsage struct {
LogID int64 `gorm:"column:log_id;type:int8;primaryKey;autoIncrement:true" json:"log_id"`
}
Method AutoIncrement does not work for postgres driver, so GEN cannot generate tag autoIncrement:true
type Employee struct {
ID string `json:"id" gorm:"primaryKey;type:INTEGER;autoIncrement;"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt time.Time `json:"deletedAt"`
Name string `json:"name" gorm:"index;size:50"`
}
@riverchu any workaround for my case to enable auto increment as also my code don't work as expected
i wonder about your use case.As far as i know, autoIncrement works when you calling autoMigrate?am i right?