Django Unique Together (with foreign keys)

You can’t. The unique_together clause is directly translated to the SQL unique index. And you can only set those on columns of a single table, not a combination of several tables. You can add validation for it yourself though, simply overwrite the validate_unique method and add this validation to it. Docs: http://docs.djangoproject.com/en/dev/ref/models/instances/#django.db.models.Model.validate_unique

How does PostgreSQL enforce the UNIQUE constraint / what type of index does it use?

create an index and not assume that the values are unique It is safe to assume that values are unique, if you have a unique index defined. That’s how unique constraints are implemented (at the time being, and probably in all future versions as well). Defining a UNIQUE constraint does effectively the same (almost, see … Read more

Can PostgreSQL have a uniqueness constraint on array elements?

The righteous path You might want to reconsider normalizing your schema. It is not necessary for everyone to “join for even the simplest query”. Create a VIEW for that. Table could look like this: CREATE TABLE hostname ( hostname_id serial PRIMARY KEY , host_id int REFERENCES host(host_id) ON UPDATE CASCADE ON DELETE CASCADE , hostname … Read more