title: How to test edit function on django? (error django.db.utils.IntegrityError: NOT NULL constraint failed)
body: <p>i try to write code for editing records and its unit test. here is my code:
  <strong>test_view.py</strong></p>
  
  <pre><code>def test_edit_address(self):
      address1 = Address.objects.create(first_name='Edith', last_name='Star', address='Some City', phone_number='123455')
      response = self.client.post(
          reverse('edit', kwargs={'address_id': address1.id}), 
          {'first_name': 'Patrick', 'last_name': 'Stars', 'address': 'Other City', 'phone_number': '0123455'})
      self.assertEqual(response.status_code, 302)
      address1.refresh_from_db()
      self.assertEqual(address1.first_name, 'Patrick')
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>from django.http import HttpResponseRedirect, HttpResponse
  from django.shortcuts import redirect, render
  from addressbooksapp.models import Address
  from django.contrib import messages
  
  def edit(request, address_id):
  
    if  request.method == 'POST':
      addresses = Address.objects.get(pk=address_id)
  
      addresses.first_name = request.POST.get('firstname_text')
      addresses.last_name = request.POST.get('lastname_text')
      addresses.address = request.POST.get('address_text')
      addresses.phone_number = request.POST.get('phone_text')
  
      addresses.save()
      messages.success(request, ('Record Has Been Edited!'))
      return redirect('home')
  
    else:
      addresses = Address.objects.get(pk=address_id) 
      return render(request, 'edit.html', {'addresses': addresses})
  </code></pre>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>from django.db import models
  
  class Address(models.Model):
      first_name = models.CharField(max_length=200)
      last_name = models.CharField(max_length=200)
      address = models.TextField()
      phone_number = models.CharField(max_length=200)
  </code></pre>
  
  <p><strong>urls.py</strong></p>
  
  <pre><code>from django.urls import path
  from addressbooksapp import views
  
  urlpatterns = [
       path('', views.home_page, name='home'),
       path('delete/&lt;address_id&gt;',views.delete, name='delete'),
       path('edit/&lt;address_id&gt;',views.edit, name='edit'),
  ]
  </code></pre>
  
  <p>But when run the test i got error "django.db.utils.IntegrityError: NOT NULL constraint failed: addressbooksapp_address.first_name"</p>