异常描述:
WARNINGS:
projects.Projects.create_time: (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 you want to have the current date as default, use `django.utils.timezone.now`
from django.db import models# Create your models here.from django.db import models
from django.utils import timezoneclass Projects(models.Model):name = models.CharField(max_length=100)create_time = models.DateTimeField(default=timezone.now)# create_time = models.DateTimeField(default=timezone.now())# 添加()报错update_time = models.DateTimeField(default=timezone.now)def __str__(self):return self.name
区别在于,timezone.now一个可调用对象在运行时执行,同时timezone.now()返回该函数的输出。
去掉()就可以了。