0PricingLogin
Go Academy · Lesson

Models and AutoMigrate

Define and migrate schema.

What Is GORM

GORM is the most popular ORM for Go. It maps Go structs to database tables so you work with objects instead of raw SQL. It supports PostgreSQL, MySQL, SQLite, and more.

  • Struct-to-table mapping
  • Automatic migrations
  • Associations and hooks

Defining a Model

A model is a Go struct. Each exported field becomes a column. Embedding gorm.Model adds ID, CreatedAt, UpdatedAt, and DeletedAt fields.

type User struct {
    gorm.Model
    Name  string
    Email string
    Age   int
}

All lessons in this course

  1. Models and AutoMigrate
  2. CRUD Operations
  3. Associations
  4. Hooks and Scopes
← Back to Go Academy