I'm trying to weaken a sql unique constraint.
Let's say I have a Human model with name and gender fields. And the name must be unique.
sql_constraints = [('name_unique', UNIQUE(name), 'Error: Name must be unique!')]
What I want is, that the name has to be unique if the gender is female.
How to achieve that?
Can I do something like:
sql_constraints = [('human_check', CHECK(gender='female' AND UNIQUE(name) OR (gender='male'), 'Error: Females must have unique names!')]
Or should I write a custom constraint?
Any other suggestions? (Like splitting the model into Males and Females)
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
About This Community
|Asked: 4/17/14, 9:34 AM|
|Seen: 1760 times|
|Last updated: 3/16/15, 8:10 AM|