'“” value has an invalid date format. It must be in YYYY-MM-DD format.'

Hello everyone,

I’m getting this error - ‘“” value has an invalid date format. It must be in YYYY-MM-DD format.’ -
I tried DateTimeField instead of DateField but still I have that kind of error. Do you have any idea how to fix it?
Thanks in advance.

models.py

class Samples(models.Model):
    last_extraction_date = models.DateField(null=True, blank=True)
    inactivation_date = models.DateField(null=True, blank=True)
    transfer_date = models.DateField(null=True, blank=True)

views.py

def addsample_row(request):
if request.method == "POST":
        if (request.POST.get('last_extraction_date') or request.POST.get('last_extraction_date') is '') \
        and (request.POST.get('inactivation_date') or request.POST.get('inactivation_date') is '') \
        and (request.POST.get('transfer_date') or request.POST.get('transfer_date') is ''):
    
           sample = Samples()

           sample.last_extraction_date = request.POST.get('last_extraction_date')
           sample.inactivation_date = request.POST.get('inactivation_date')
           sample.transfer_date = request.POST.get('transfer_date')
 
           sample.save()
           messages.success(request, "New sample is added successfully!")
           return HttpResponseRedirect("/")

   else:
        return render(request, 'addsample.html')

How is your form defined?

1 Like

Sorry for the late answer!

The problem is actually at the part of importing csv file. I want to leave last_extraction_date column blank and upload it to db. But it gives me above error. When I fill it, it works fine. At model, I put null and blank True but still not working…

new_sample = Samples()
       try:
           if(Samples.objects.get(p_id_s=listItem[0])):
                Samples.objects.filter(p_id_s=listItem[0]).update(**new_item_details)
       except Samples.DoesNotExist:
               new_sample.__dict__.update(new_item_details)
               new_sample.save()

Are there spaces between the delimiters for those rows where last_extraction_date doesn’t have a value? If so, those need to be removed.
(blank=True doesn’t mean that you can have spaces in the value, it just means that a null string can be interpreted as a null value.)

1 Like