Django model validation skipping for unique_together constraint in Django 4.2
Could someone explain I've tried everything I can think of but I'm encountering a perplexing situation where my Django model's `unique_together` constraint seems to be ignored when saving new instances. I have a model defined like this: ```python from django.db import models class MyModel(models.Model): field1 = models.CharField(max_length=100) field2 = models.CharField(max_length=100) class Meta: unique_together = (('field1', 'field2'),) ``` When I attempt to save instances of `MyModel` with the same values for `field1` and `field2`, I expect a `ValidationError` to be raised. However, this is not happening, and I'm able to create duplicate entries without any errors. For example: ```python # This works fine even if both are identical instance1 = MyModel(field1='test', field2='duplicate') instance1.save() instance2 = MyModel(field1='test', field2='duplicate') instance2.save() # Should raise an error ``` Iβve also checked my database and confirmed that both entries are being stored. I have tested this with both SQLite and PostgreSQL backends, and the behavior is consistent. I've overridden the `save` method in my model to add custom validation, but even that doesnβt seem to trigger. Here's what I tried: ```python def save(self, *args, **kwargs): if MyModel.objects.filter(field1=self.field1, field2=self.field2).exists(): raise ValidationError('This entry already exists.') super().save(*args, **kwargs) ``` However, when I run the code, it still allows the duplicate. I've also made sure that my form validation is set up correctly and that I'm not bypassing it. Am I missing something in the configuration for `unique_together`, or is there another reason why it would not be enforced? Any insights would be greatly appreciated! This is happening in both development and production on CentOS. Hoping someone can shed some light on this.