django南迁,USE_TZ = True [英] django south migration and USE_TZ=True
问题描述
我已经使用 django.utils.timezone.now()$ c $更改了我所有的代码以使用
感知时间
c>
我将datetimefield改为使用 default = timezone.now
,并在设置中设置 USE_TZ = True
.py
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
更改后,我运行了south schemamigration命令,它不会接收到数据库字段的更改。
After the changes, I ran south schemamigration command and it doesn't pick up the database fields change.
如果重要,我使用的是南方0.7.6和postgresql。
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?
推荐答案
基于Bryce的答案,这些是我们用来将我们的南方迁移转换为时区感知的bash脚本:
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/;}' {} \;
在OS X上使用10.11.5El Capitan。
Used on OS X 10.11.5 "El Capitan."
这篇关于django南迁,USE_TZ = True的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!