首页 > 解决方案 > 我似乎无法在没有错误的情况下在 django 中使用 DateTimeField

问题描述

我的 django 博客应用程序具有参数、标题、发布日期、正文和图像。当我在管理页面上创建博客模型时出现错误。这是代码的样子。

ProgrammingError at /admin/blog/blog/add/
column "pub_date" is of type integer but expression is of type timestamp with time zone
LINE 1: ..._date", "image", "body") VALUES ('My first blog', '2020-04-0...
                                                             ^
HINT:  You will need to rewrite or cast the expression.

这是我创建的模型:

from django.db import models

class Blog(models.Model):
    title = models.CharField(max_length=250)
    pub_date = models.DateTimeField()
    image = models.ImageField(upload_to='images/')
    body = models.TextField()

标签: pythondjangopostgresql

解决方案


推荐阅读