когда я делаю makemigrations, я получаю эту ошибку
You are trying to add the field 'post_date' with 'auto_now_add=True' to userasking without a default; the database needs something
to populate existing rows.
1) Provide a one-off default now (will be set on all existing rows)
2) Quit, and let me add a default in models.py
Select an option:
в этом коде я пытаюсь установить поле даты и нахожу эту ошибку. когда я делаю поиск по этой проблеме, я нахожу, что мне нужно установить значение по умолчанию, и я установил:
from django.utils import timezone
post_date = models.DateField(auto_now_add=True, default=timezone.now())
когда я устанавливаю значение по умолчанию, я получаю эту ошибку:
WARNINGS:
community.UserAsking.post_date: (fields.W161) Fixed default value provided.
HINT: It seems you set a fixed date / time / datetime value as default for this field. This may not be what you want. If y
ou want to have the current date as default, use `django.utils.timezone.now`
как можно Я пропускаю эту проблему и успешно мигрирую
models.py
class UserAsking(models.Model):
userprofile = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
title = models.CharField(max_length=100, blank=False, help_text='Be specific and imagine you’re asking a question to another person')
question = models.TextField(max_length=500, blank=False, help_text='Include all the information someone would need to answer your question')
field = models.CharField(max_length=20, choices=CHOICE, default='Technology', help_text='Add the field to describe what your question is about')
post_date = models.DateField(auto_now_add=True)