What version of Go are you using (go version)?

go version go1.13.10 linux/amd64

Which database and its version are you using?

PostgreSQL 12.2 (but as I understand, the issue is not related to DB)

Go ORM Version

v2_dev github.com/jinzhu/gorm v1.9.13-0.20200429154718-9dfed613db7e

Please provide a complete runnable program to reproduce your issue. IMPORTANT

package main

import (
    "github.com/jinzhu/gorm"
    "github.com/jinzhu/gorm/dialects/sqlite"
    "net"
    "fmt"
)

var db *gorm.DB

func init() {
    var err error

    db, err = gorm.Open(sqlite.Open("test.db"), nil)

    if err != nil {
        panic(err)
    }
}

type TestModel struct {
    gorm.Model
    Host string
    IP net.IP
}

func main() {
    fmt.Println(db.AutoMigrate(&TestModel{}))
}

Issue description

When I start the test code above (go run main.go) I get errors:

2020/05/02 13:02:30 /tmp/test/main.go:29
[error] unsupported data type: <nil>

2020/05/02 13:02:30 /tmp/test/main.go:29
[error] unsupported data type: <nil>

2020/05/02 13:02:30 /tmp/test/main.go:29
[error] unsupported data type: <nil>

2020/05/02 13:02:30 /tmp/test/main.go:29
[error] unsupported data type: <nil>

I found the place in GORM code which generates such error: https://github.com/jinzhu/gorm/blob/v2_dev/schema/schema.go in a function Parse (lines 62-66):

func Parse(dest interface{}, cacheStore *sync.Map, namer Namer) (*Schema, error) {
    modelType := reflect.ValueOf(dest).Type()
    for modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Ptr {
        modelType = modelType.Elem()
    }

    if modelType.Kind() != reflect.Struct {
        if modelType.PkgPath() == "" {
            return nil, fmt.Errorf("%w: %+v", ErrUnsupportedDataType, dest) // Here is the error
        }
        return nil, fmt.Errorf("%w: %v.%v", ErrUnsupportedDataType, modelType.PkgPath(), modelType.Name()) // and here.
    }

    if v, ok := cacheStore.Load(modelType); ok {
        return v.(*Schema), nil
    }

The problem is that in case of Go Zero value the line: return nil, fmt.Errorf("%w: %+v", ErrUnsupportedDataType, dest) generates an error text which does not help a lot (In my humble opinion).

Could you, please, modify the line to include in error either a Model Field Name or at least a Field reflect.Kind?

Is it possible to modify GORM fields reflection to work with byte Slices as BLOBS?

Comment From: github-actions[bot]

This issue has been automatically marked as stale as it missing playground pull request link, checkout https://github.com/go-gorm/playground for details, it will be closed in 2 days if no further activity occurs.

Comment From: nccapo

Anyone fix this issue?