Reputation: 29
type Competition struct {
ID uint64 `gorm:"primaryKey;autoIncrement"`
UserID uint64
Title string `gorm:"size:100;not null" validate:"required,min=10,max=100"`
Description string `gorm:"size:5000;not null" validate:"required,min=100,max=5000"`
Latitude float64 `gorm:"not null" validate:"required"`
Longitude float64 `gorm:"not null" validate:"required"`
Address string `gorm:"size:1000;not null" validate:"required,max=1000"`
StartingDate string `gorm:"not null" validate:"required,min=10,max=10"`
StartingTime string `gorm:"not null" validate:"required,min=5,max=5"`
EndingTime string
Images []string
CreatedAt uint64 `gorm:"autoCreateTime"`
UpdatedAt uint64 `gorm:"autoUpdateTime:milli"`
// relationships
Users []*User `gorm:"many2many:participant;"`
}
I am using postgresql and need to add list data type column but []string is not working and generating exception while migrating models to db.
Upvotes: 0
Views: 638
Reputation: 11807
As metalisticpain stated through a post link that you need to use pq.StringArray
type postgres for it to work
Just change Images
Field as below
Images pq.StringArray `gorm:"type:text[]"`
Don't forget to import github.com/lib/pq
library which contains pq.StringArray
implementation
And make sure while inserting data you wrap it with pq.Array
Upvotes: 1