What’s the difference between auto_now and auto_now_add?

Md Sadiqul Islam
1 min readMar 1, 2023

--

auto_now and auto_now_add are two field options in Django that determine how the values of fields are set when a model instance is saved.

The auto_now option is used to set the value of the field to the current date and time every time the model instance is saved, regardless of whether it is being created or updated. This is useful for fields that should always reflect the last time the instance was saved, such as a "last updated" timestamp.

The auto_now_add option, on the other hand, is used to set the value of the field to the current date and time only when the model instance is created. This is useful for fields that should reflect the time the instance was created, such as a "date created" timestamp.

In summary, the key difference between auto_now and auto_now_add is that auto_now updates the field value every time the instance is saved, while auto_now_add sets the field value only when the instance is created.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response