POSTGRESQL-DJANGO-日期中没有时区的时间



我正在使用Postegressql数据库开发一个项目的Django。

我刚刚创建了一个这样的模型:

from django.db import models
from members.models import CustomUser

class Article(models.Model):
title = models.CharField(max_length=250)
body = models.TextField()
custom_user = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True)
updated_at = models.DateTimeField(auto_now=True, blank=True, null=True)
def __str__(self):
return self.title
class Meta:
ordering = ["-created_at"]
def save(self, *args, **kwargs):
super().save(*args, **kwargs)

当我尝试迁移时,我会遇到以下问题:ERREUR:没有时区日期,无法转换类型时间

在我的数据库中,我的表中有";"没有时区的时间";。

你有什么想法吗?谢谢

尝试使用DateField而不是DateTimeFieldDateField不存储时区。

阅读此处的文档:https://docs.djangoproject.com/en/4.1/ref/models/fields/#datefield

这可能会有所帮助:

from django.db import models
from members.models import CustomUser

class Article(models.Model):
title = models.CharField(max_length=250)
body = models.TextField()
custom_user = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
created_at = models.DateField(auto_now_add=True, blank=True, null=True) # --> changed to DateField
updated_at = models.DateField(auto_now=True, blank=True, null=True) # --> changed to DateField
def __str__(self):
return self.title
class Meta:
ordering = ["-created_at"]
def save(self, *args, **kwargs):
super().save(*args, **kwargs)

最新更新