geektutu/7days-golang · error
invalid sql type %s (%s)
Error message
invalid sql type %s (%s)
What it means
Same 'invalid sql type' panic in the day7-migrate stage of gee-orm. During migration the schema is parsed and each field's type is mapped via the sqlite3 dialect; a field kind outside the supported switch (bool/int/float/string/[]byte/time.Time) panics with this message.
Source
Thrown at gee-orm/day7-migrate/dialect/sqlite3.go:38
case reflect.Bool:
return "bool"
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32,
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uintptr:
return "integer"
case reflect.Int64, reflect.Uint64:
return "bigint"
case reflect.Float32, reflect.Float64:
return "real"
case reflect.String:
return "text"
case reflect.Array, reflect.Slice:
return "blob"
case reflect.Struct:
if _, ok := typ.Interface().(time.Time); ok {
return "datetime"
}
}
panic(fmt.Sprintf("invalid sql type %s (%s)", typ.Type().Name(), typ.Kind()))
}
// TableExistSQL returns SQL that judge whether the table exists in database
func (s *sqlite3) TableExistSQL(tableName string) (string, []interface{}) {
args := []interface{}{tableName}
return "SELECT name FROM sqlite_master WHERE type='table' and name = ?", args
}
View on GitHub (pinned to cf36443821)
Solutions
- Normalize the field to a supported type or serialize it into a string/[]byte column
- Add the needed kind mapping to the sqlite3 dialect
- Split complex fields into separate tables
Example fix
// before
type Product struct {
Attributes map[string]string
}
// after
type Product struct {
Attributes string // JSON encoded map
} Defensive patterns
Strategy: validation
Validate before calling
for _, f := range reflect.VisibleFields(reflect.TypeOf(Product{})) {
if !isSQLiteMappable(f.Type) {
log.Fatalf("migration blocked: field %s (%s) unsupported", f.Name, f.Type)
}
} Type guard
func isSQLiteMappable(t reflect.Type) bool {
if t == reflect.TypeOf(time.Time{}) { return true }
switch t.Kind() {
case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
reflect.Float32, reflect.Float64, reflect.String, reflect.Slice:
return true
}
return false
} Try / catch
defer func() {
if r := recover(); r != nil {
if s, ok := r.(string); ok && strings.HasPrefix(s, "invalid sql type") {
err = fmt.Errorf("migration failed on unsupported field: %s", s)
} else { panic(r) }
}
}() Prevention
- Audit models for map/slice/struct fields before running migrations
- Store serialized JSON in string columns for complex data
- Run migration against a test DB in CI to catch schema issues early
When it happens
Trigger: Running geeorm migration (Open/MigrateModel) on a struct that contains a slice, map, nested struct, or other unmappable field type.
Common situations: Migrating a table whose model grew complex fields; version changes where a string field became a custom type; developers modeling documents in relational columns.
Related errors
- invalid sql type %s (%s)
- invalid sql type %s (%s)
- invalid sql type %s (%s)
- invalid sql type %s (%s)
- panic(p)
AI-assisted analysis of geektutu/7days-golang@cf36443821 (2026-09-03).
Data as JSON: /api/errors/2ef2414e961828eb.
Report an issue: GitHub.