I use PonyORM, and I want to add a unique constraint on a combination of two fields.
Here's an example (PonyEditor link : https://editor.ponyorm.com/user/lial_slasher/DoubleConstraint).
I have two tables, Parent and Child. A parent can have many childs, but not two with the same name. Which means I want to add a unique constraint on the couple (parent, name) of the Child table.
It's pretty straightforward, but I can't figure out the python syntax to do it.
You can use
composite_keywhich according to the document, is equivalent toUNIQUEon several columns in SQL.example:
Here, the
nameattribute in theChildclass will be unique together with theparentwhich means each parent can have exactly one child with a specific name. This is equal to the following SQL query: