I have the following function in which I try to add missing columns to a PostgreSQL database's table with GORM. The data is coming from a HTTP request and is JSON.
router.POST("/up", func(c *gin.Context) {
raw, _ := c.GetRawData()
parsed, _ := gabs.ParseJSON(raw)
db, err := gorm.Open("postgres", "host=" + os.Getenv("HOST") + " port=5432 user=" + os.Getenv("USER") + " dbname=something password=" + os.Getenv("PASSWORD"))
[...]
db.AutoMigrate(parsed.Data())
defer db.Close()
})
This fails with a strange error (German).
(pq: Bezeichner in Anführungszeichen hat Länge null bei »""«)
Which translated means the following.
(pq: Quoted identifier has a length of zero at »""«)
The JSON I create the HTTP request with looks like this.
{
"FieldA": "blah",
"FieldB": "nope",
"Hostname": "yo.host.com",
"Updated": "2018.06.13 21:00:33"
}
Any ideas how to do this? The idea is to add a column to the db each time a new field is sent to the backend.