Skip to content

GORM inserts zero timestamps (0000-00-00 00:00:00) even with strict SQL mode enabled #7654

@PENTIK007

Description

@PENTIK007

Your Question

I'm encountering an issue with GORM where zero timestamps are being inserted into a MySQL database even when strict SQL mode is enabled, which shouldn't allow such values. Here's the details:
The database column is of type timestamp.
In my Go code, the corresponding field is of type time.Time.
The database has strict mode enabled (which should prevent inserting invalid timestamps like 0000-00-00 00:00:00).
However, when I insert a record using GORM without explicitly setting this time field (leaving it as the zero value of time.Time), the insertion succeeds, and the database ends up with 0000-00-00 00:00:00 for that column. This contradicts the strict mode configuration, which should reject such values.
I suspect GORM might be doing some special handling for timestamp fields that bypasses the database's strict mode checks. Has anyone encountered this issue?
Any insights or solutions would be greatly appreciated. Thank you!

The document you expected this should be explained

Expected answer

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions