当我启动日期字段名称为dob的请求时,dob的各自值为“ dob”:“ 1996-10-25”
Model.py
ax = powiaty.plot(column=var, cmap='Reds', categorical=True,
legend=True, ax=ax, edgecolor='black'
)
views.py
class Register_model(models.Model):
UserId = models.CharField(max_length=255,default='',blank=True,null=True)
ISpinId = models.CharField(max_length=255,primary_key=True, unique=True,default='', blank=True,null = False)
email = models.CharField(max_length=250, unique=True)
first_name = models.CharField(max_length=250, default="",null = False)
last_name = models.CharField(max_length=250, default="",null = False)
dob = models.DateField(auto_now_add=False, auto_now=False)
password = models.CharField(max_length=255,blank=False,null = False)
gender = models.CharField(max_length=50,default="",null = False)
nationality = models.CharField(max_length=100,default="",null = False)
错误:
@permission_classes((AllowAny,))
class User_RegisterAPIViews(APIView):
# Serializer Initilization
print("dasf")
serializers = serializers.Register_Serializer
# Post method Declarations
def post(self, request):
request.POST._mutable = True
print(request.data)
request.data['ISpinId'] = etc.random_number_generate(request.data['first_name'], request.data['last_name'])
password = request.data['password']
print(request.data['dob'])
playersCategory, age = etc.age_convert(request.data['dob'], request.data['gender'])
request.data['players_category'] = playersCategory
request.data['age'] = age
form_data = serializers.Register_Serializer(data=request.data)
if form_data.is_valid():
print("formdata",form_data)
form_data.save() # File Save
我创建了一个新数据库,数据库迁移,也应用了新迁移,但是仍然出现此错误[“”值的日期格式无效。它必须为YYYY-MM-DD格式。“] < / p>
答案 0 :(得分:0)
检查模型的任何日期参数,例如默认值空引号替换为
model.DateField(blank= True,null=True)