{"record":{"id":"f32c5785aa037246","repo":"go-gorm/gorm","slug":"unsupported-data-type","errorCode":null,"errorMessage":"unsupported data type","messagePattern":"unsupported data type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"schema/schema.go","lineNumber":33,"sourceCode":"\t\"gorm.io/gorm/logger\"\n)\n\ntype callbackType string\n\nconst (\n\tcallbackTypeBeforeCreate callbackType = \"BeforeCreate\"\n\tcallbackTypeBeforeUpdate callbackType = \"BeforeUpdate\"\n\tcallbackTypeAfterCreate  callbackType = \"AfterCreate\"\n\tcallbackTypeAfterUpdate  callbackType = \"AfterUpdate\"\n\tcallbackTypeBeforeSave   callbackType = \"BeforeSave\"\n\tcallbackTypeAfterSave    callbackType = \"AfterSave\"\n\tcallbackTypeBeforeDelete callbackType = \"BeforeDelete\"\n\tcallbackTypeAfterDelete  callbackType = \"AfterDelete\"\n\tcallbackTypeAfterFind    callbackType = \"AfterFind\"\n)\n\n// ErrUnsupportedDataType unsupported data type\nvar ErrUnsupportedDataType = errors.New(\"unsupported data type\")\n\ntype Schema struct {\n\tName                      string\n\tModelType                 reflect.Type\n\tTable                     string\n\tPrioritizedPrimaryField   *Field\n\tDBNames                   []string\n\tPrimaryFields             []*Field\n\tPrimaryFieldDBNames       []string\n\tFields                    []*Field\n\tFieldsByName              map[string]*Field\n\tFieldsByBindName          map[string]*Field // embedded fields is 'Embed.Field'\n\tFieldsByDBName            map[string]*Field\n\tFieldsWithDefaultDBValue  []*Field // fields with default value assigned by database\n\tRelationships             Relationships\n\tCreateClauses             []clause.Interface\n\tQueryClauses              []clause.Interface\n\tUpdateClauses             []clause.Interface","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/go-gorm/gorm/blob/1d6ce99528060be18a42be09aca8d39efcb47f28/schema/schema.go#L15-L51","documentation":"schema.ErrUnsupportedDataType is returned by schema.Parse when a model cannot be turned into a Schema. The common causes: the model (or Dest of a query) is not a struct, is a nil/unsupported kind, or contains a field whose Go type has no usable serializer/data type (including fields whose underlying kind is invalid after following pointers).","triggerScenarios":"Passing a non-struct as Model/Dest (db.Find(1), db.Find(&count)), declaring a field of an unsupported type with no Scanner/Valuer implementation and no serializer tag, or a model type that is an interface/untyped nil at runtime.","commonSituations":"Calling db.Model(&user).Count(&count) but passing count wrongly (e.g. &count where count is not int - that is a different error); fields of custom types lacking driver.Valuer/sql.Scanner; generics code where the type parameter does not constrain to struct; version upgrades tightening type validation.","solutions":["Ensure the model is a plain struct (or pointer to one) with an exported, defined type.","Give custom field types Value()/Scan() methods (driver.Valuer / sql.Scanner) or a serializer gorm tag.","For counts and scalars use proper destinations: var count int64; db.Model(&User{}).Count(&count).","Inspect the exact field via the wrapped error context (set a logger to see the failing statement)."],"exampleFix":"// before\ntype Meta struct{ Data chan int } // chan has no data type\n\n// after\ntype Meta struct{ Data string `gorm:\"type:json\"` }","handlingStrategy":"validation","validationCode":"func validModel(v interface{}) error {\n    rv := reflect.Indirect(reflect.ValueOf(v))\n    if rv.Kind() != reflect.Struct {\n        return fmt.Errorf(\"%T: %w\", v, schema.ErrUnsupportedDataType)\n    }\n    for i := 0; i < rv.NumField(); i++ {\n        ft := rv.Type().Field(i)\n        if ft.Type.Kind() == reflect.Chan || ft.Type.Kind() == reflect.Func {\n            return fmt.Errorf(\"field %s has unsupported type %s\", ft.Name, ft.Type)\n        }\n    }\n    return nil\n}","typeGuard":"func isStructOrStructPointer(v interface{}) bool {\n    return reflect.Indirect(reflect.ValueOf(v)).Kind() == reflect.Struct\n}","tryCatchPattern":"if err := db.Find(&dest).Error; err != nil {\n    if errors.Is(err, schema.ErrUnsupportedDataType) {\n        return fmt.Errorf(\"bad model/dest type %T\", dest)\n    }\n    return err\n}","preventionTips":["Implement driver.Valuer/sql.Scanner (or a serializer tag) for every custom field type.","Compile-time guard models: instantiate them in a schema.Parse smoke test at startup.","Use typed destinations for counts/plucks."],"tags":["gorm","schema","model","data-type","validation"],"backgroundTag":null,"analyzedSha":"1d6ce99528060be18a42be09aca8d39efcb47f28","analyzedAt":"2026-08-15T13:01:23.433Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}