Django - Date error



  • In an attempt to recruit a team python manage.py makemigrations There's a mistake:

    django.core.exceptions.ValidationError: ["'' value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."]
    

    It's weird, because I have default meaning everywhere:

    import datetime
    

    import django
    from django.db import models

    Create your models here.

    class Article(models.Model):
    class Meta():
    db_table = 'article'

    title = models.CharField(max_length=200)
    text = models.TextField()
    author = models.CharField(max_length=50)
    date = models.DateTimeField(default=django.utils.timezone.now)
    
    # Метод для корректного отображения заголовков статей
    def __str__(self):
        return self.title
    
    def getSmallText(self):
        if len(self.text) > 200:
            return self.text[:200]
        else:
            return self.text
    

    class Comment(models.Model):
    class Meta():
    db_table = 'comment'

    text = models.TextField(default=None)
    article = models.ForeignKey(Article)
    name = models.CharField(max_length=50)
    date = models.DateTimeField(default=django.utils.timezone.now)
    

    What should I do?



  • Try to check that you have the right time zone in the django settings.py, and you get the meaning:

    django.utils.timezone.now
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2