在Django以下模型(Python的3.4,Django的1.7.4瓦特/ PostgreSQL的)需要为它DateTimeField字段的默认值:Django的DateTimeField字段默认
from django.utils import timezone as django_tz
class AvailabilityRuleOnce(AvailabilityRule):
class Meta:
app_label = 'configuration'
objects = AvailabilityRuleOnceManager()
starting_time = django_models.DateTimeField(
'Starting time for the rule', default=django_tz.now, blank=True
)
ending_time = django_models.DateTimeField(
'Ending time for the rule', default=django_tz.now, blank=True
)
当试图应用迁移,下面抛出异常:
django.db.utils.ProgrammingError: column "ending_time" cannot be cast automatically to type timestamp with time zone
HINT: You might need to specify "USING ending_time::timestamp with time zone".
在Django文档,他们建议使用此选项,我也试过,可以在网上找到,如添加“auto_now_add =真”,但它不工作或者其他选项。我究竟做错了什么?
真正的问题是,Django的迁移不会使用datafield擦除列,在更新默认值之前这是必需的。 – Ricardo