Forge Models
Overview
Define data models using github.com/forgego/forge/schema. This skill focuses on model structure that drives code generation: fields, relations, metadata, and hooks.
When to Use
- •The task mentions model structs, fields, relations, Meta options, or hooks.
- •You need to change model schemas or codegen inputs.
- •The user asks about renames, constraints, or lifecycle hooks.
Quick Start
- •Create or edit a model struct embedding
schema.BaseSchema. - •Implement
Fields(),Meta(),Relations(), andHooks(). - •Run
forge generate, thenforge makemigrationsandforge migrate.
Common Tasks
- •Add or change fields and options (required, default, unique, max length).
- •Add relations (ForeignKey, OneToOne, ManyToMany).
- •Configure
Meta()(table name, ordering, indexes, unique constraints). - •Add lifecycle hooks in
Hooks().
Gotchas
- •Renaming fields or relations requires migrations and can affect existing data.
- •Always run
forge generateafter model changes. - •Model changes drive admin and API behavior, so keep naming consistent.