Hello everybody, sorry I don’t know exactly in which forum to ask that question.
Here is a simple model for a user action:
class UserAction(models.Model):
action = models.CharField(...)
created_at = models.DateTimeField(auto_now_add=True)
For development purpose, I want to make a command to run periodically that fakes user activity throughout the day. In other words, daily at say 8:00 in the morning, my script will bulk create like thousands of UserAction rows for the day, each with different fake created_at values.
The problem is, auto_now_add doesn’t let me save a date manually. Instead, the value will always be the date of creation of the row. auto_now_add is a requirement that cannot be permanently removed from the model.
How could I sort of disable that behaviour just the time it takes to run that script? Basically what I’d see for my command is something like this:
Actually it looks like the answer was super simple. Contrary to my assumption, auto_now_add is not enforced at DB level. So just “disable” it in the model field in the script.