1

I've changed all my code to use aware-time by using django.utils.timezone.now() I changed datetimefield to use default=timezone.now, and set USE_TZ=True in settings.py

After the changes, I ran south schemamigration command and it doesn't pick up the database fields change.

I'm using the south 0.7.6 and postgresql if that matters.

Here's the detailed change I made to make my entire site timezone aware.
how do I make my site timezone aware?

Community
  • 1
  • 1
eugene
  • 39,839
  • 68
  • 255
  • 489

2 Answers2

0

If you use south, and change USE_TZ=False to USE_TZ=True, all your old migrations will likely break, and you'll get errors like:

RuntimeWarning: DateTimeField received a naive datetime (XXX)
while time zone support is active

I have not found a way to have south track changes in settings.py. What I've done is alter the actual migration files. These each have a number and are in the migrations subdirectory.

For each one that fails, add from django.utils import timezone, and modify any DateTimeField fields the same way as you did in your main code (making them time zone aware, or eliminating a specific non-timezone default date).

Alternately you can try to reset your south migration history.

Community
  • 1
  • 1
Bryce
  • 8,313
  • 6
  • 55
  • 73
0

Building on Bryce's answer, these are the bash scripts we used to convert our south migrations to timezone-aware:

$ cd mysite/mainapp/migrations
$ find ./ -type f -exec sed -i -e 's/datetime.datetime.now/timezone.now/g' {} \;
$ find ./ -type f -exec sed -i -e '/import datetime/{G;s/$/from django.utils import timezone/;}' {} \;

Used on OS X 10.11.5 "El Capitan."

CubeJockey
  • 2,209
  • 8
  • 24
  • 31