mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Doctrine fails to apply DEFAULT CURRENT_TIMESTAMP for DateTime field #7436
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Legend999 on GitHub (Oct 27, 2024).
Bug Report
Summary
Doctrine fails to apply the default timestamp for a field defined with
DEFAULT CURRENT_TIMESTAMP. When persisting an entity without manually setting the date, it raises a "column cannot be null" error, despite the database schema having a default value set.Current behavior
Expected behavior
Doctrine should use the default timestamp set in the schema (
DEFAULT CURRENT_TIMESTAMP), allowing to create new entities without explicitly setting the value.How to reproduce
CURRENT_TIMESTAMP, as shown below:Additional information
The issue seems to be specific to PHP/Doctrine, as running a raw SQL
INSERT INTO messages (message) VALUES ('message')correctly assigns the sent_at field to the current timestamp.@goforthanddie commented on GitHub (Dec 9, 2024):
I am experiencing the same problem with ORM 3.3.0.0. However, it helped when I added 'insertable: false' as additional parameter for the column :).
@greg0ire commented on GitHub (Nov 20, 2025):
I think this is just a documentation issue, what you've done makes sense @goforthanddie .