Hi everyone!
I’m here to ask you all about your opinion on auto_now and auto_now_add :
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
I’ve been considering dropping these from my project for the following reasons:
1. No overrides (#16583)
It’s inconvenient that these fields can’t be overridden. Use-cases:
- Tests. I want to create test records with explicit
created_at/updated_atfor integration tests - Migrations. I want to create production records with explicit
created_at/updated_atwhen migrating historical data
I know there are ways to work around it, but it’s inconvenient to do so
2. created_at and updated_at differs slightly (#16745)
When creating a record, created_at and updated_at differs slightly
It’s not a huge issue, but it would be better if they were the same because that’s what I would expect
#22995 proposes deprecating these parameters. Also, see this django-developers discussion . It seems like the consensus used to be that these params shouldn’t be used
Personally, I like using these params. It’s nice to have an official Django feature for this. I would rather address their limitations than remove them
Question: should developers avoid using auto_now and auto_now_add?