-2

I have mentioned two fields(Name, Age) in my golang Struct after few days I have added one more fields in my database(Name,Age, Salary ) not in golandg struct.It shows errors like(Error 1364: Field 'salary' doesn't have a default value). How to ignore fileds in my struct dynamically

   type Employee struct {
 
      Name string `json:"name"
       Age int `json:"age"

   }

In future i will add more fileds but i don't want mention in struct

Volker
  • 40,468
  • 7
  • 81
  • 87
  • 7
    Show the code that generates the error. It's hard to guess what you're doing. You need to actually supply that information yourself. Also, consider taking the [tour] read [ask] and how to make a [mre]. – super Sep 23 '21 at 13:07

1 Answers1

0

Based on the error you are getting, it seems like you are trying to insert a row into a MySQL database, and the new row you added does not have a default value. So your options are to :

  1. Add a default value to the new column - See: https://dev.mysql.com/doc/refman/8.0/en/data-type-defaults.html
  2. Add a field for the column into your Go struct and supply a value for it.