Django - SQLite 上的 DateTimeField 查询与 MySQL
Django - DateTimeField query on SQLite vs MySQL
此查询 returns MySQL 中的空查询集,但在 SQLite 中有效:
commented_this_month = Post.objects.filter(comment__created__month=now.month)
我的模型真的很简单:
class Comment(models.Model):
comment = models.TextField()
author = models.ForeignKey(User, on_delete=models.CASCADE)
created = models.DateTimeField(default=timezone.now)
post = models.ForeignKey(Post, on_delete=models.CASCADE)
有什么我遗漏的吗?
我使用 mysql_tzinfo_to_sql 实用程序生成了 mysql.time_zone* 表:
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
此查询 returns MySQL 中的空查询集,但在 SQLite 中有效:
commented_this_month = Post.objects.filter(comment__created__month=now.month)
我的模型真的很简单:
class Comment(models.Model):
comment = models.TextField()
author = models.ForeignKey(User, on_delete=models.CASCADE)
created = models.DateTimeField(default=timezone.now)
post = models.ForeignKey(Post, on_delete=models.CASCADE)
有什么我遗漏的吗?
我使用 mysql_tzinfo_to_sql 实用程序生成了 mysql.time_zone* 表:
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql