1👍
✅
What you’re doing is updating private key. Django creates new instance in this case. It is is actually Django’s way to copy a record. The INSERT
not UPDATE
query is performed by ORM.
If you change your code to:
class Machines(models.Model):
…
ip_addr = models.CharField(max_length=50, unique=True, …
…
Django will interprete your edit action correctly as the primary key won’t change.
Next time use django-debug-toolbar
to see what query is performed by Django ORM.
Source:stackexchange.com