Reputation: 1061
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
.
Upvotes: 8
Views: 15119
Reputation: 171
type TextDump struct {
*gorm.Model
Title string `gorm:"size:50" json:"title" binding:"required"`
Text string `gorm:"text" json:"text" binding:"required"`
Count int `json:"count"`
ChannelID int `json:"channel_id" binding:"required"`
}
Upvotes: -1
Reputation:
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
Upvotes: 8
Reputation: 479
Just create with a blank tag.
type Post struct {
gorm.Model
Content string ``
}
P.S. I'm using Gorm v1.20.12 with Postgres 11.8
Upvotes: 0