I am trying to create a TEXT
column using Gorm ORM but the column is still created as VARCHAR(225)
.
Below is the struct I want to migrate to a table.
type TextDump struct {
*gorm.Model
Title string `gorm:"varchar(50)" json:"title" binding:"required"`
Text string `gorm:"text" json:"text" binding:"required"`
Count int `json:"count"`
ChannelID int `json:"channel_id" binding:"required"`
}
The text
column is created as VARCHAR
instead of TEXT
.
Tags are optional to use when declaring models, GORM supports the following tags: Tags are case insensitive, however camelCase is preferred.
Gorm is an Irish (Gaelic) word meaning "blue". Ignorance is bliss => Ignorance means not having the blues. => Ignorance = Gormless. QED.
Reposting @Narro's comment here for better discoverability (I too had to check the comments).
You should use the tag name type
before the column type:
type TextDump struct {
*gorm.Model
Text string `gorm:"type:text"`
// ...
}
Reference: Gorm Field Tags
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With