有一个 date
charfield ,当我之前将日期保存为字符串时。但是现在我将字段从 charfield 更改为 datetimefield 并删除了所有以前的数据。
date = models.DateTimeField(default=timezone.now)
在本地运行良好,但在生产中尝试迁移时会引发以下错误。我删除了列、模型、注释和取消注释、删除并再次创建该字段、返回到以前的迁移并再次迁移,但所有这些都没有帮助。
django.db.utils.ProgrammingError: column "date" cannot be cast automatically to type timestamp with time zone
HINT: You might need to specify "USING date::timestamp with time zone".
如何正确解决问题?使用 django 1.8、python 2.7 和 postgres
最佳答案
对于在尝试将整数列转换为时间戳时在 Google 上发现此问题的任何人:
ALTER TABLE my_table
ALTER COLUMN my_column
TYPE timestamp with time zone
USING to_timestamp(my_column);
关于python - 无法自动转换列 "date"以键入带时区的时间戳 django/postgres,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43965016/