As I look at the sqlall for a models.py that contains unique_together statements, I don’t notice anything that looks like enforcement.
In my mind, I can imagine that this knowledge might help the database optimize a query, like so:
“I have already found a row with spam 42 and eggs 91, so in my search for eggs 91, I no longer need to check rows with spam 42.”
Am I right that this knowledge can be helpful to the DB?
Am I right that it is not enforced this way (ie, it is only enforced by the ORM)?
If yes to both, is this a flaw?
Here’s an example how this should look. Assume that you have model:
Running sqlall it returns:
When this model is properly synced on DB it has unique constraint (postgres):