title: NOT NULL constraint failed: users_userprofile.user_id
body: <p>I am trying to insert <code>django form</code> data inside the <code>UserProfile</code> model in my app. I tried using the <code>django shell</code> and <code>views.py</code> but I keep getting this error. </p>
  
  <p>Models.py</p>
  
  <pre><code>from django.db import models
  from django.contrib.auth.models import User
  # Create your models here.
  
  
  class UserProfile(models.Model):
      user = models.OneToOneField(User, on_delete=models.CASCADE)
      section = models.CharField(max_length=255, blank=True)
      year = models.IntegerField(null=True, blank=True)
      course = models.CharField(max_length=255, blank=True)
      qrcode = models.CharField(max_length=255, blank=True)
      present = models.BooleanField(default=False)
  
      def __str__(self):
          return self.user.username
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>@staticmethod
  def generate_qr(request):
      if request.method == "POST":
          form = MakeAttendance(request.POST)
          if form.is_valid():
              course = form.cleaned_data.get('courses')
              section = form.cleaned_data.get('section')
              year = form.cleaned_data.get('year')
              profile = UserProfile.objects.get_or_create(user=request.user)
              userobj = UserProfile(qrcode=unique_id)
              userobj.save().filter(course=course, section=section, year=year)
      return redirect('/users/dashboard')
  </code></pre>
  
  <p>This question has been answered many times here, but none of the solutions worked for me. I tried Creating a user profile with <code>get_or_create</code> method. I tried deleting my entire database and making migrations again. I manually tried to pass the user ID but nothing. </p>