1

I added a field to one of my models:

date_created= models.DateTimeField(auto_now=True)

When I ran manage.py migrate it asked for a default. I could not add a default to the models as default is mutually exclusive of auto_now=True. It wouldn't allow me.

So I punched in a quick default string: "12-12-2015" and went on my way.

However, every time I run my tests I get an ugly error:

RuntimeWarning: DateTimeField BusinessAccount.date_created received a naive datetime (2015-09-13 02:14:32.898795) while time zone support is active.

I've changed the models in response:

date_created= models.DateTimeField(default=datetime.now)

But the error remains. I tried squashing the migration where I added the original value, but it didn't seem to do anything.

EDIT: Looking closer at the output, it seems that datetime.now is submitting a string instead of a datetime object and is now causing the same problem.

How can I fix this?

Adam Starrh
  • 6,428
  • 8
  • 50
  • 89

1 Answers1

1

If you are looking to store the creation time use auto_now_add=True

date_created= models.DateTimeField(auto_now_add=True)
Nidhin
  • 628
  • 7
  • 16