gorm-conventions

Explain GORM default naming conventions for Go structs mapped to database tables.

Updated Apr 4, 2026
One-click install
npx skills add https://github.com/liurida/gorm-development-skill --skill gorm-conventions
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: gorm-conventions
Source: https://github.com/liurida/gorm-development-skill/tree/main/conventions
Command: npx skills add https://github.com/liurida/gorm-development-skill --skill gorm-conventions

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It removes the guesswork of how GORM maps Go structs to database tables, columns, primary keys, and timestamps, enabling developers to write concise models without manual configuration.

Core Features & Use Cases

  • Default Naming Insight: Understand how GORM converts struct and field names to snake_case tables and columns, and when it automatically adds primary key and timestamp fields.
  • Override Guidance: Learn how to customize table names with the Tabler interface, change column names via tags, and adjust timestamp behavior.
  • NamingStrategy Configuration: Apply project‑wide naming rules such as table prefixes, singular table names, and custom replacers.
  • Use Case: When onboarding a new Go service that uses GORM, quickly determine the expected database schema for existing structs or decide how to enforce your organization’s naming standards.

Quick Start

Ask the skill: “What table name does GORM assign to a struct named User?”

Frequently Asked Questions about gorm-conventions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How does GORM map a Go struct to a database table name and columns?

GORM automatically converts Go struct names and field names to snake_case for database tables and columns. It also infers primary keys and timestamp fields unless explicitly overridden by struct tags or custom configurations.

How do I override the default table name for a GORM model?

You can override the default GORM table name by implementing the Tabler interface in your Go struct. Alternatively, apply project-wide naming rules by configuring a custom NamingStrategy to enforce table prefixes or singular table names.

How do I configure project-wide naming conventions in GORM?

You configure project-wide naming conventions in GORM by setting a custom NamingStrategy. This allows you to apply global rules such as table prefixes, singular table names, and custom character replacers across all mapped structs.

Does GORM automatically add primary key and timestamp fields to Go structs?

Yes, GORM automatically recognizes fields named ID as primary keys and fields like CreatedAt or UpdatedAt as timestamp columns. You can customize this default behavior using GORM tags or struct configuration.

Can I customize column names in GORM without changing the struct field?

You can customize column names in GORM by using struct tags. This allows you to map a Go struct field to a specific database column name without altering the struct field name itself.

What are the limitations of relying on GORM default naming conventions?

Relying on GORM default naming conventions limits you to snake_case transformations and automatic primary key detection. Complex database schemas or organizational naming standards require manual overrides via tags or a custom NamingStrategy configuration.