Naming Strategy
GORM converts struct and field names to database identifiers. By default, struct names are pluralized and snake_cased for table names; field names become snake_case column names.
Default behavior
Post→ tablepostsUserProfile→ tableuser_profilesCreatedAt→ columncreated_at
Overriding table name
func (Post) TableName() string {
return "posts"
}
Overriding column names
Email string `gorm:"column:email_address"`
Custom naming in GORM
Configure GORM at connect time with NamingStrategy:
db, err := gorm.Open(dialector, &gorm.Config{
NamingStrategy: schema.NamingStrategy{
SingularTable: true, // Post → post, not posts
},
})