Say I have a model:
class User(models.Model):
username = models.CharField(max_length=30, unique=True)
email = models.EmailField(unique=True)
When I create a User
, django needs to first check the unique constraints and does so with two individual queries like
SELECT (1) AS "a" FROM "accounts_user" WHERE "accounts_user"."username" = 'aoeu' LIMIT 1
SELECT (1) AS "a" FROM "accounts_user" WHERE "accounts_user"."email" = 'aoeu@aoeu.com' LIMIT 1
How do I tell django to check both constraints in one query like
SELECT (1) AS "a" FROM "accounts_username" WHERE "accounts_user"."username" = 'aoeu' OR "accounts_user"."email" = 'aoeu@aoeu.com' LIMIT 1