Categories
Python Answers

How to fix all records in database have the same value in date field with Python Django?

Spread the love

To fix all records in database have the same value in date field with Python Django, we set the default value to datetime.now or auto_now_add set to True.

For instance, we write

date = models.DateTimeField(auto_now_add=True, blank=True)

or

date = models.DateTimeField(default=datetime.now, blank=True)

to set the created date field to datetime.now() with

default=datetime.now

or

auto_now_add=True

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *