Description

I have 2 struct:

//like gorm.Model
type Model struct { 
    Id        uint           `json:"id" gorm:"type: serial;"`
    CreatedAt time.Time      `json:"createdAt"`
    UpdatedAt time.Time      `json:"updatedAt"`
    DeletedAt gorm.DeletedAt `json:"-"`
}

type DictionaryDetail struct {
    Model

    DictionaryId uint   `json:"dictionaryId" gorm:"type:bigint;not null;default:0;"`
    Label        string `json:"label" gorm:"not null;default:''"`
    Sort         int    `json:"sort" gorm:"not null;default:0"`
    Status       *bool  `json:"status" gorm:"not null;default"`
    Value        int    `json:"value" gorm:"not null;default:0;"`
}

When "CREATE TABLE",it will cause error like: 错误: 对表 "dictionary_detail" 的字段 "dictionary_id" 指定了多遍默认值 (SQLSTATE 42601) [3.261ms] [rows:0] CREATE TABLE "dictionary_detail" ("id" serial,"created_at" timestamptz,"updated_at" timestamptz,"deleted_at" timestamptz,"dictionary_id" serial NOT NULL DEFAULT 0,"label" text NOT NULL DEFAULT '',"sort" bigint NOT NULL DEFAULT 0,"status" boolean NOT NULL DEFAULT false,"value" bigint NOT NULL DEFAULT 0,PRIMARY KEY ("id"))

The type of "DictionaryId" I set is bigint,but in sql statement it is serial. If I change the type of Id in Model to "primarykey",it will be OK.

Is this a bug?Because "DictionaryId" field include the text "id"?

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: a631807682

If I change the type of Id in Model to "primarykey",it will be OK.

We keep guessing that the id is the primary key, so there will be no change. Did not find this problem, please upgrade gorm and postgres version.

[5.529ms] [rows:0] CREATE TABLE "dictionary_details" ("id"  serial,"created_at" timestamptz,"updated_at" timestamptz,"deleted_at" timestamptz,"dictionary_id" bigint NOT NULL DEFAULT 0,"label" text NOT NULL DEFAULT '',"sort" bigint NOT NULL DEFAULT 0,"status" boolean NOT NULL DEFAULT false,"value" bigint NOT NULL DEFAULT 0,PRIMARY KEY ("id"))

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking