In my struct, i have the following
type Task struct {
gorm.Model
Id int `json:"id" gorm:"primaryKey;AUTO_INCREMENT"`
UserId int `json:"user_id" gorm:"Index;not null" validate:"required"`
TaskId int `json:"task_id" gorm:"Index;not null" validate:"required"`
JobId int `json:"job_id" gorm:"not null" validate:"required"`
Latitude float64 `json:"latitude" gorm:"not null" validate:"required"`
Longitude float64 `json:"longitude" gorm:"not null" validate:"required"`
StartAt time.Time `json:"start_at"`
EndAt time.Time `json:"end_at"`
CreatedAt time.Time
UpdatedAt time.Time
}
and i have this function that saves to the table with the following
{ "user_id": 1,
"location":[5748.5445, 89790.454],
"latitude": 89790.454,
"longitude": 5748.5445,
"startAt": "2030-10-30T10:58:00.000Z",
"endAt": "2031-10-30T10:58:00.000Z"
}
func CreateTask(c *fiber.Ctx) error {
var opentask models.JobOpenTask
if err := c.BodyParser(&opentask); err != nil {
return c.Status(400).JSON(err.Error())
}
db.DB.Db.Create(&opentask)
return c.Status(200).JSON("OK")
}
When this runs, it still saves the record on the DB but I expect it to throw and error when it tries to save since it is not null in my struct but why is it able to save to the Db without throwing an error?