I m trying to create a table in postgresql with gorm automigrate. I have a struct in which I have field of type as another struct (embedded struct). The datatype of this filed is json. But while doing automigrate this field is not getting created as a column in the table
I have tried to change the type of embedded struct to pointer, it didn't help
type Home struct{
HomeID string `gorm:"type:varchar(65);primary_key"`
Address string `gorm:"type:varchar(200)" json:"address"`
Location Coordinates `gorm:"type:json" json:"location"`
}
type Coordinates struct{
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
}
I want to create location
column with json
as datatype.
But this filed is not getting create in automigrate
I could get it done by changing the datatype of Location
field from Coordinates
to []byte
, this will solve the problem of automigrate.
But i have a json in the following way
{
"address": "some_address",
"location":{
"latitude": 34.9393932,
"longitude": 28.2348793
}
}
I need to unmarshal this json to the Home
struct.
json.Unmarshal
is failing if I change the datatype of Location
to []byte