Why is the date field not saved?

Hi! My model:

class Nom(models.Model):
    title = models.CharField(max_length=150, verbose_name='Наименование', )
    izm=models.ForeignKey(Unit,verbose_name='Ед.изм.',on_delete=models.PROTECT)
    category = models.ForeignKey(Category, verbose_name='Категория', on_delete=models.PROTECT)
    srok=models.IntegerField(blank=True,default=0)
    updated_at = models.DateTimeField(auto_now=True, verbose_name='Создан')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='Обновлен')
    def __str__(self):
        return self.title

If I just add an record, everything works correctly. But an error occurs when editing:
“django.db.utils.IntegrityError: NOT NULL constraint failed: store_nom.created_at”
I think it has to do with the field ‘created_at’, But it should be saved automatically, right?

def NomSave(request):
    if request.method =='POST':
        form=NomForm(request.POST)
        print(request.POST)
        if form.is_valid():
            uid=request.POST['unitid']
            title=request.POST['title']
            izm=Unit.objects.get(pk=request.POST['izm'])
            category = Category.objects.get(pk=request.POST['category'])
            srok = request.POST['srok']
            if uid=='':
                newrecord=Nom(title=title,izm=izm,category=category,srok=srok)
            else:
                print(uid)
                newrecord = Nom(title=title, izm=izm, category=category, srok=srok,id=uid)
            newrecord.save()
            un = Nom.objects.values('id', 'title', 'izm__title','category__title','srok')
            unit_data = list(un)
            print(unit_data)
            print('ok')
            return JsonResponse({'status':'Save','unit_data':unit_data})
        else:
            print('notvalid')
            return JsonResponse({'status':0})

def NomUpdate(request):
    if request.method=='POST':
        id=request.POST.get('sid')
        unit=Nom.objects.get(pk=id)
        unit_data={'id':unit.id,'title':unit.title,'cat':unit.category.title,'idcat':unit.category.id,
                   'izm':unit.izm.title,'idizm':unit.izm.id,'srok':unit.srok}
        print(unit_data)
        return JsonResponse(unit_data)
    else:
        return JsonResponse({'status':0,})

AJAX:

<script>
////////////////////////////////////////////Добавление строки Номенклатура/////////////////
$('#nom-form').on('submit',function(e){
output='';
event.preventDefault();
console.log('Кнопка добавить');
let sid=$('#unit_id').val();
let _csr=$("input[name=csrfmiddlewaretoken]").val();
let _tlt=$('#idtitle').val();
let _izm=$('#idizm').val();
let _idc=$('#idcat').val();
let _srk=$('#idsrok').val();

mydata={
unitid:sid,
csrfmiddlewaretoken:_csr,
title:_tlt,
izm:_izm,
category:_idc,
srok:_srk
}
console.log(mydata);
$.ajax({
url:'/NomSave/',
method:"POST",
data:mydata,
dataType:"json",

success:function(data){
x=data.unit_data;
if (data.status == 'Save'){
for(i=0;i<x.length;i++){
output +='<tr><td style="width:420px;" class="align-middle fixed">'+ x[i].title +'</td>'+
'<td style="width:180px;" class="align-middle fixed">'+ x[i].izm__title +'</td>'+
'<td style="width:300px;" class="align-middle fixed">'+ x[i].category__title +'</td>'+
'<td style="width:90px;" class="align-middle fixed text-center">'+ x[i].srok +'</td>'+
'<td class="text-center align-middle fixed" style="width:45px;"><input data-sid="#" data-update='+x[i].id+' class="btn-nom-update " value="Update" type="image" src="../static/images/update.png" style="width:25px;" > </td>'+
'<td class="text-center align-middle fixed" style="width:50px;"><input data-sid='+x[i].id+' data-del="#" class="btn-nom-delete " value="Update" type="image" src="../static/images/del.png" style="width:25px;" > </td></tr>'


};
$('#tbody').html(output)
    output='';
    $('#unit_id').val('');
    $("form")[0].reset();
};
if (data.status == 0){alert('NO')};
}
});

});
////////////////////////////////////////Конец добавления строки Номенклатура/////////////////////////////

////////////////////////////////////////Удаление строки/////////////////////////////////////////////////
/////////////////////////////Delete SPR
$('#tbody').on('click','.btn-nom-delete',function(e){
event.preventDefault();
console.log('Delete Click');
let id=$(this).attr('data-sid');
let csr=$("input[name=csrfmiddlewaretoken]").val();
mydata={sid:id, csrfmiddlewaretoken:csr,};
mythis=$(this);
$.ajax({
url:'/NomDelete/',

method:'GET',
data:mydata,
dataType:"json",

success:function(data){
if(data.status =='Del'){$(mythis).closest("tr").fadeOut();}
if (data.status == 0){
    alert('Запись не удалена, потому что она используется в других документах...' );
    }
},
});
});

///////////////////////////////////////Конец удаления строки/////////////////////////////////////////////
///////////////////////////////////////Обновление строки Номенклатура////////////////////////////////////
$('#tbody').on('click','.btn-nom-update',function(e){
event.preventDefault();
console.log('Clicked Update');

let id=$(this).attr('data-sid');

let csr=$("input[name=csrfmiddlewaretoken]").val();
console.log(id);

mydata={sid:id, csrfmiddlewaretoken:csr,};
mythis=$(this);

$.ajax({
url:'/NomUpdate/',
method:'POST',
data:mydata,
dataType:"json",

success:function(data){
$('#unit_id').val(data.id);
$('#idtitle').val(data.title);
$("#idcat").val(data.idcat).change();
$("#idizm").val(data.idizm).change();
$("#idsrok").val(data.srok);
},
});
});
///////////////////////////////////////Конец обновления строки Номенклатура//////////////////////////////

</script>

I found a bug in the code! The topic can be closed