Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a TEXT column with Go Gorm

Tags:

go

go-gorm

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.

like image 269
Olu Udeh Avatar asked Dec 18 '19 23:12

Olu Udeh


People also ask

Is Gorm case sensitive?

Tags are optional to use when declaring models, GORM supports the following tags: Tags are case insensitive, however camelCase is preferred.

What is Gorm?

Gorm is an Irish (Gaelic) word meaning "blue". Ignorance is bliss => Ignorance means not having the blues. => Ignorance = Gormless. QED.


1 Answers

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

like image 124
anon Avatar answered Oct 04 '22 00:10

anon