title: Why does Django auto_now_add fail with not null on insert or update
body: <p>I am trying to implement a data warehouse. So the django system will query an api at regular intervals to update the database. I am using client ids as the primary key which might be the problem but when I do save I obviously want it to create or update.</p>
  <p>I get this error whatever I do!</p>
  <p>django.db.utils.IntegrityError: null value in column &quot;created&quot; violates not-null constraint</p>
  <p>So originally I just had my model like this:</p>
  <pre><code>class PersonalTaxClient(models.Model):
  
   created = models.DateTimeField(auto_now_add=True)
   updated = models.DateTimeField(auto_now=True)
   invoice_client = models.ForeignKey(InvoiceClient, blank=True, null=True, on_delete=models.PROTECT)
   client_name = models.CharField(max_length=100)
   email = models.CharField(max_length=100)
  </code></pre>
  <p>Then I tried:</p>
  <pre><code>class PersonalTaxClient(models.Model):
  
      created = models.DateTimeField(editable=False)
      updated = models.DateTimeField()
      client_code = models.CharField(max_length=20, primary_key=True) 
      invoice_client = models.ForeignKey(InvoiceClient, blank=True, null=True, on_delete=models.PROTECT)
      client_name = models.CharField(max_length=100)
      email = models.CharField(max_length=100)
  #    history = HistoricalRecords()
  
      def save(self, *args, **kwargs):
          ''' On save, update timestamps '''
          print(timezone.now())
          if not self.client_code:
              self.created = timezone.now()
          self.modified = timezone.now()
          return super(PersonalTaxClient, self).save(*args, **kwargs)
  </code></pre>
  <p>and try to update like this:</p>
  <pre><code>&gt;&gt;&gt; from sbsite.models import PersonalTaxClient
  &gt;&gt;&gt; p = PersonalTaxClient(client_code=&quot;HHH001&quot;, client_name=&quot;Bob&quot;)
  &gt;&gt;&gt; p.save()
  
  </code></pre>
  <p>I get the same error. I've read about 20 other SO pages but am none the wiser..............!</p>