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

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

Postgresql: Conditionally unique constraint

PostgreSQL doesn’t define a partial (i.e. conditional) UNIQUE constraint – however, you can create a partial unique index. PostgreSQL uses unique indexes to implement unique constraints, so the effect is the same, with an important caveat: you can’t perform upserts (ON CONFLICT DO UPDATE) against a unique index like you would against a unique constraint. … Read more

MySQL – Make an existing Field Unique

ALTER IGNORE TABLE mytbl ADD UNIQUE (columnName); For MySQL 5.7.4 or later: ALTER TABLE mytbl ADD UNIQUE (columnName); As of MySQL 5.7.4, the IGNORE clause for ALTER TABLE is removed and its use produces an error. So, make sure to remove duplicate entries first as IGNORE keyword is no longer supported. Reference

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