【发布时间】:2014-07-16 12:52:54
【问题描述】:
在我的 models.py 中,我有一些具有这种属性的模型:
timestamp = models.TimeField(default=0)
我想把它们改成:
timestamp = models.DateTimeField(default=0)
使用
python manage.py schemamigration app --auto
在第一个实例中起作用。 但是
python manage.py migrate app
导致此错误:
django.db.utils.ProgrammingError: column "timestamp" cannot be cast to type timestamp with time zone
所以我需要以某种方式使这种铸造成为可能。对于每次没有日期的时间,我都想设置一个默认日期(例如昨天)。我怎样才能做到这一点? 我只在 SO 上找到了this,由于那个错误,这根本没有帮助。 顺便说一句:我正在使用 postgres 和 python3。
感谢您的帮助!
如果这样更容易的话,我可以直接在数据库上使用 SQL(不带南)
【问题讨论】:
-
你可能想要的东西叫做数据迁移:south.readthedocs.org/en/latest/tutorial/…
-
这篇文章有帮助吗? stackoverflow.com/a/14362743/1628832
标签: python sql django postgresql