title: NOT NULL constraint failed: users_profile.user_id?
body: <p>When I update the user's profile I keep getting the error <strong>NOT NULL constraint failed: users_profile.user_id</strong>. I have tried to fix it by setting the argument commit to False <code>form.save(commit =False)</code> then performing <code>form.save()</code>. My question is how can I update my profile and the user field of the Profile model is populated automatically by the currently authenticated user.</p>
  <p>Here is my code...</p>
  <p><strong>users/views.py</strong></p>
  <pre><code>@login_required(login_url=reverse_lazy(&quot;users:login&quot;))
  def profile(request,slug):
  
  if request.method == &quot;POST&quot;:
      form = ProfileUpdateForm(request.POST)
      if form.is_valid():
          form.save(commit = False)
          form.cleaned_data[&quot;user&quot;] = request.user
          form.save()
          messages.success(request, &quot;Profile updated successfully!&quot;)
          return redirect(&quot;users:profile&quot;, kwargs=&quot;profile&quot;)
      
  else:
      profile = Profile.objects.get(user__username = slug)
      form = ProfileUpdateForm()
  
  context = {&quot;profile&quot;:profile,&quot;form&quot;:form}
  
  return render(request, &quot;users/profile.html&quot;, context)
  </code></pre>
  <p><strong>users/models.py</strong></p>
  <pre><code>class Profile(models.Model):
      user = models.OneToOneField(User,on_delete=models.CASCADE)
      bio = models.TextField(blank = True)
      image = models.ImageField(default = &quot;default.jpg&quot;, upload_to = &quot;profile_pics&quot;)
      city = models.CharField(max_length=20,blank = True)
      url = models.URLField(blank = True)
  
      def __str__(self):
          return f&quot;{self.user.username}'s profile&quot;
  </code></pre>
  <p><strong>users/signals.py</strong></p>
  <pre><code>@receiver(post_save, sender = User)
  def create_profile(sender,instance,created,**kwargs):
      if created:
          Profile.objects.create(user=instance)
  
  
  @receiver(post_save, sender = User)
  def create_profile(sender,instance,created,**kwargs):
      instance.profile.save()
  </code></pre>
  <p><strong>users/forms.py</strong></p>
  <pre><code>class ProfileUpdateForm(forms.ModelForm):
      class Meta:
          model = Profile
          exclude = [&quot;user&quot;]
  </code></pre>