Adding struct data breaks calls

182 Views Asked by At

I'm using gorp and the *DBMap.addTableWithName() function to create tables.

If I have the following:

...
type S1 struct {
  Id    int    `db:"id"`
  Name  string `db:"name"`
  Value string `db:"value"`
}

dbmap := &gorp.DbMap{Db: db, Dialect: gorp.PostgresDialect{}}

dbmap.AddTableWithName(S1{}, "s1Table").SetKeys(true, "Id")

...

Which works as expected.

If I modify the struct to this

...
type S1 struct {
  Id    int    `db:"id"`
  Name  string `db:"name"`
  Value string `db:"value"`
  Extra string `db:"extra"`
}
...

Then the table isnt modified with the new struct structure.

If I modify the database manually

ALTER TABLE s1Table ADD COLUMN extra text;

then run any queries I get back sql: Scan error on column index 3, name "extra": converting NULL to string is unsupported

I've looked through the GoDocs for gorp but nothing has jumped out at me as a solution.

My Question is - is it possible for gorp to manage these table changes? If not then how would it be done to not result in a converting NULL to string is unsupported error.

0

There are 0 best solutions below