NOT NULL constraint failed: auctions_comment.auction_id

I’m having this error in my code and I have used adjusted my code using this NOT NULL constraint failed - #4 by KenWhitesell and other links but the problem persist.

Could you please tell me what I am doing wrong

MODELS.PY

class Auction(models.Model):
    ABSTRACT = 'AB'
    MODERN = 'MN'
    ILLUSTRATION = 'IN'

    select_category = [
        ('ABSTRACT', 'Abstract'),
        ('MODERN', 'Modern'),
        ('ILLUSTRATION', 'Illustration')
    ]

    title = models.CharField(max_length=25)
    description = models.TextField()
    current_bid = models.IntegerField(null=False, blank=False)
    image_url = models.URLField(verbose_name="URL", max_length=255, unique=True, null=True, blank=True)
    category = models.CharField(
        choices=select_category,
        max_length=12,
        default=MODERN,
        null=True, blank=True
    )
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.title

    class Meta:
        ordering = ['-created_at']


class Comment(models.Model):
    auction = models.ForeignKey(Auction, related_name='comments', on_delete=models.CASCADE)
    name = models.CharField(max_length=25)
    description = models.TextField(max_length=150)
    created_at = models.DateTimeField(auto_now_add=True, null=True)

    def __str__(self):
        return '%s, - %s' % {self.aunction.title, self.name}

    class Meta:
        ordering = ['-created_at']

FORMS.PY

class CommentForm(forms.ModelForm):

    class Meta:
        model = Comment
        fields = ['name', 'description']

VIEWS.PY

def listing_detail(request, listing_id):
    try:
        detail = get_object_or_404(Auction, pk=listing_id)
    except Auction.DoesNotExist:
        messages.add_message(request, messages.ERROR, "This is not available") 
        return HttpResponseRedirect(reverse("index"))

    bid_count = Bids.objects.filter(auction=listing_id).count()
    bid_form= BidForm()     

    if request.method == 'POST':
        comment_form = CommentForm(request.POST)

        if comment_form.is_valid():
            new_comment = comment_form.save(commit=False)
            new_comment.detail = detail
            new_comment.save()

        else:
            comment_form = CommentForm()
    else:
        comment_form = CommentForm()
    context = {'detail': detail,
                'bid_count': bid_count, 
                'bid_form': bid_form, 
                'comment_form': comment_form}

    return render(request, 'auctions/details.html', context)

Please post the complete traceback message that you are receiving in the console where you’re running runserver.

You need to set the auction property on new_comment before you save similar to what you’re doing with the detail property.