Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing autoIncrement in postgres table schema output #88

Closed
wmh opened this issue Mar 17, 2022 · 3 comments
Closed

Missing autoIncrement in postgres table schema output #88

wmh opened this issue Mar 17, 2022 · 3 comments
Assignees

Comments

@wmh
Copy link

wmh commented Mar 17, 2022

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"`
}
@tr1v3r tr1v3r transferred this issue from go-gorm/gen Mar 19, 2022
@tr1v3r
Copy link
Member

tr1v3r commented Mar 19, 2022

Method AutoIncrement does not work for postgres driver, so GEN cannot generate tag autoIncrement:true

@kateile
Copy link

kateile commented Mar 21, 2022

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

@tr1v3r
Copy link
Member

tr1v3r commented Mar 21, 2022

i wonder about your use case.As far as i know, autoIncrement works when you calling autoMigrate?am i right?

@jinzhu jinzhu closed this as completed in d3403e4 Oct 8, 2022
@jinzhu jinzhu reopened this Oct 8, 2022
@jinzhu jinzhu closed this as completed in e6551c7 Oct 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants