go-gorm/gorm · error
unsupported relations
Error message
unsupported relations
What it means
Error "unsupported relations" thrown in go-gorm/gorm.
Source
Thrown at errors.go:19
package gorm
import (
"errors"
"gorm.io/gorm/logger"
)
var (
// ErrRecordNotFound record not found error
ErrRecordNotFound = logger.ErrRecordNotFound
// ErrInvalidTransaction invalid transaction when you are trying to `Commit` or `Rollback`
ErrInvalidTransaction = errors.New("invalid transaction")
// ErrNotImplemented not implemented
ErrNotImplemented = errors.New("not implemented")
// ErrMissingWhereClause missing where clause
ErrMissingWhereClause = errors.New("WHERE conditions required")
// ErrUnsupportedRelation unsupported relations
ErrUnsupportedRelation = errors.New("unsupported relations")
// ErrPrimaryKeyRequired primary keys required
ErrPrimaryKeyRequired = errors.New("primary key required")
// ErrModelValueRequired model value required
ErrModelValueRequired = errors.New("model value required")
// ErrModelAccessibleFieldsRequired model accessible fields required
ErrModelAccessibleFieldsRequired = errors.New("model accessible fields required")
// ErrSubQueryRequired sub query required
ErrSubQueryRequired = errors.New("sub query required")
// ErrInvalidData unsupported data
ErrInvalidData = errors.New("unsupported data")
// ErrUnsupportedDriver unsupported driver
ErrUnsupportedDriver = errors.New("unsupported driver")
// ErrRegistered registered
ErrRegistered = errors.New("registered")
// ErrInvalidField invalid field
ErrInvalidField = errors.New("invalid field")
// ErrEmptySlice empty slice found
ErrEmptySlice = errors.New("empty slice found")View on GitHub (pinned to 1d6ce99528)
Solutions
- Check that the relation name passed to Preload/Association matches the struct field name exactly.
- Ensure the related model is a registered struct with proper gorm foreignKey/references tags.
- Remove or fix relations that use unsupported field types (e.g. maps or unexported fields).
Example fix
Verify the relation name exists on the schema before preloading: if _, ok := stmt.Schema.Relationships.Relations[name]; ok { db.Preload(name) } When it happens
Trigger: Thrown at errors.go:19 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of go-gorm/gorm@1d6ce99528 (2026-08-15).
Data as JSON: /api/errors/e1af0d039dc53cab.
Report an issue: GitHub.