We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
表中有一个 id 字段,我并不想将它设置为主键,因此,我设置了 primaryKey:false,但是不起作用。
primaryKey:false
type Test struct { ID int64 `gorm:"autoIncrement:false;primaryKey:false;column:id;type:bigint;not null" json:"-"` }
查看源码后,发现了这一段:
prioritizedPrimaryField := schema.LookUpField("id") if prioritizedPrimaryField == nil { prioritizedPrimaryField = schema.LookUpField("ID") } if prioritizedPrimaryField != nil { if prioritizedPrimaryField.PrimaryKey { schema.PrioritizedPrimaryField = prioritizedPrimaryField } else if len(schema.PrimaryFields) == 0 { prioritizedPrimaryField.PrimaryKey = true schema.PrioritizedPrimaryField = prioritizedPrimaryField schema.PrimaryFields = append(schema.PrimaryFields, prioritizedPrimaryField) } }
我不明白 else if len(schema.PrimaryFields) == 0 都明确表示没有主键字段了,为什么硬是要塞一个 id 字段作为主键?
else if len(schema.PrimaryFields) == 0
设置 primaryKey:false 后,不管是不是 id 字段,都不应该将字段设置为主键。
The text was updated successfully, but these errors were encountered:
jinzhu
No branches or pull requests
Your Question
表中有一个 id 字段,我并不想将它设置为主键,因此,我设置了
primaryKey:false
,但是不起作用。查看源码后,发现了这一段:
我不明白
else if len(schema.PrimaryFields) == 0
都明确表示没有主键字段了,为什么硬是要塞一个 id 字段作为主键?Expected answer
设置 primaryKey:false 后,不管是不是 id 字段,都不应该将字段设置为主键。
The text was updated successfully, but these errors were encountered: