title: Why Am I getting an Integrity Error while uploading csv file to django app?
body: <p>While uploading a csv file I'm getting an Integrity Error. I have a correctly working QuizApp which has models about Quiz, Questions and Answers. But I've created another app csvs to upload csv file with Questions and Answers. While I'm trying to upload a CSV file I'm getting that error. The file isn't uploaded to the website.</p>
  <pre><code>IntegrityError at /something/admin/csvs/csv/add/
  null value in column &quot;quiz_id&quot; of relation &quot;csvs_csv&quot; violates not-null constraint
  DETAIL:  Failing row contains (11, csvs/example_KLOIQJK.csv, 2022-09-15 05:46:25.666689+00, f, null)
  </code></pre>
  <pre><code>csvs.models.py
  
  class Csv(models.Model):
      file_name = models.FileField(upload_to=&quot;csvs&quot;)
      uploaded = models.DateTimeField(auto_now_add=True)
      activated = models.BooleanField(default=False)
  </code></pre>
  <pre><code>csvs.forms.py
  from django import forms
  from csvs.models import Csv
  
  
  class CsvModelForm(forms.ModelForm):
      class Meta:
          model = Csv
          fields = (&quot;file_name&quot;,)
  </code></pre>
  <pre><code>csvs.views.py
  from django.shortcuts import render
  from django.http import HttpResponse
  from .forms import CsvModelForm
  
  # Create your views here.
  
  
  def upload_file_view(request):
      form = CsvModelForm(request.POST or None, request.FILES or None)
      if form.is_valid():
          form.save()
          form = CsvModelForm()
      return render(request, &quot;csvs/import.html&quot;, {&quot;form&quot;: form})
  </code></pre>
  <pre><code>quiz.models.py
  from django.db import models
  from django.contrib.auth import get_user_model
  from django.urls import reverse, reverse_lazy
  import uuid
  
  
  class Quiz(models.Model):
      id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
      title = models.CharField(max_length=200)
      short_description = models.CharField(max_length=500)
      resolution_time = models.PositiveIntegerField(
          help_text=&quot;Quiz Duration in minutes&quot;, default=15
      )
      number_of_questions = models.PositiveIntegerField(default=1)
      author = models.ForeignKey(
          get_user_model(),
          on_delete=models.CASCADE,
      )
      is_public = models.BooleanField(default=False)
      required_score_to_pass = models.IntegerField(
          help_text=&quot;Required score in %&quot;, default=50
      )
  
      def __str__(self):
          return f&quot;Quiz title: {self.title}&quot;
  
      def get_absolute_url(self):
          return reverse(&quot;quiz_detail&quot;, args=[str(self.id)])
  
      def get_absolute_url_edit(self):
          return reverse(&quot;quiz_edit&quot;, args=[str(self.id)])
  
      def get_absolute_url_questions_edit(self):
          return reverse(&quot;quiz_questions_edit&quot;, args=[str(self.id)])
  
      def get_absolute_url_delete(self):
          return reverse(&quot;quiz_delete&quot;, args=[str(self.id)])
  
      def get_absolute_url_my_quizes(self):
          return reverse(&quot;my_quiz&quot;)
  
      def get_absolute_url_answer_edit(self):
          return reverse(&quot;question_answer_edit&quot;)
  
      def get_absolute_url_create(self):
          return reverse(&quot;quiz_create&quot;)
  
      def get_absolute_url_play(self):
          return reverse(&quot;quiz_play&quot;, args=[str(self.id)])
  
  
  class Question(models.Model):
      quiz = models.ForeignKey(
          Quiz,
          on_delete=models.CASCADE,
          related_name=&quot;questions&quot;,
      )
      content = models.CharField(max_length=255)
      id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
  
      def __str__(self):
          return self.content
  
  
  class Answer(models.Model):
      content = models.CharField(max_length=255)
      question = models.ForeignKey(
          Question,
          on_delete=models.CASCADE,
          related_name=&quot;answers&quot;,
      )
      is_correct = models.BooleanField(default=False)
  
      def __str__(self):
          return self.content
  
      def is_that_correct_answer(self):
          return self.is_correct
  
  
  class Attempt(models.Model):
      user = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
      quiz = models.ForeignKey(Quiz, on_delete=models.CASCADE)
      score = models.SmallIntegerField(default=1)
      has_passed = models.BooleanField(default=False)
      attempt_date = models.DateTimeField(auto_now_add=True)
  </code></pre>
  <p>Any ideas?</p>