[Django]-Django.db.utils.IntegrityError: NOT NULL constraint failed

2👍

You may need to pass instance request.user.profile to the form.

def complete_profile(request):
    if request.user.is_authenticated():
        if request.method == 'POST':
            form = ProfileForm(request.POST, instance=request.user.profile)
            if form.is_valid():
                #form.instance.user = request.user
                form.save()
            return render(request, 'home.html')
        else:
            form = ProfileForm()
            return render(request, 'complete_profile.html', {'form': form})
    else:
        return render(request, 'login.html')

2👍

form = ProfileForm(request.POST,instance=request.user.profile)
          if form.is_valid():
              form.save()

try this

Leave a comment