-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Open
Labels
Description
Description
When using a size
constraint in the struct tag, that can't be parsed as a number correctly, the size constraint is silently ignored and thus later not applied to the database. I've run into this because of a typo in the struct tag, where I did something like this
type Foo struct {
Bar string `gorm:"size:32,index`
}
Notice the ,
vs ;
.
I would've expected the migration to fail on this because the settings aren't correctly parseable but sadly, it didn't.
I spelunked the code a little and I think
Lines 215 to 219 in b881483
if num, ok := field.TagSettings["SIZE"]; ok { | |
if field.Size, err = strconv.Atoi(num); err != nil { | |
field.Size = -1 | |
} | |
} |
schema.err
in that case (and in some other cases too, maybe?). I don't know the code base well enough to judge that though.