go-gorm/gorm · error

invalid value, should be pointer to struct or slice

Error message

invalid value, should be pointer to struct or slice

What it means

Error "invalid value, should be pointer to struct or slice" thrown in go-gorm/gorm.

Source

Thrown at errors.go:43

	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")
	// ErrDryRunModeUnsupported dry run mode unsupported
	ErrDryRunModeUnsupported = errors.New("dry run mode unsupported")
	// ErrInvalidDB invalid db
	ErrInvalidDB = errors.New("invalid db")
	// ErrInvalidValue invalid value
	ErrInvalidValue = errors.New("invalid value, should be pointer to struct or slice")
	// ErrInvalidValueOfLength invalid values do not match length
	ErrInvalidValueOfLength = errors.New("invalid association values, length doesn't match")
	// ErrPreloadNotAllowed preload is not allowed when count is used
	ErrPreloadNotAllowed = errors.New("preload is not allowed when count is used")
	// ErrDuplicatedKey occurs when there is a unique key constraint violation
	ErrDuplicatedKey = errors.New("duplicated key not allowed")
	// ErrForeignKeyViolated occurs when there is a foreign key constraint violation
	ErrForeignKeyViolated = errors.New("violates foreign key constraint")
	// ErrCheckConstraintViolated occurs when there is a check constraint violation
	ErrCheckConstraintViolated = errors.New("violates check constraint")
)

View on GitHub (pinned to 1d6ce99528)

Solutions

  1. Pass a pointer to a struct or slice, e.g. db.Find(&users) not db.Find(users).
  2. Check that the destination is addressable (a pointer).
  3. Avoid passing map or primitive values as the model/destination.

Example fix

Pass a pointer to struct or slice: db.Find(&users) // not db.Find(users)

When it happens

Trigger: Thrown at errors.go:43 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/d8ffbc43fc4734bd. Report an issue: GitHub.