I have a table in OpenERP/PostgreSQL with the following columns: name
and description
.
I added the following validation for unique name:
_sql_constraints = [('unique_name', 'unique(name)', 'A record with the same name already exists.')]
It works fine but it is case sensitive. Currently, it accepts values such as "Mickey", "MICKEY" and "mickey":
Wrong Way:
--------------------------
| name | description |
--------------------------
| mickey | not a mouse |
--------------------------
| MICKEY | not a mouse |
--------------------------
| Mickey | not a mouse |
--------------------------
Is there a way to revise the validation code so that it will not allow users to add several values such as "Mickey", "MICKEY" and "mickey"? How can I make the unique key validation case insensitive?
Right Way:
--------------------------------
| name | description |
--------------------------------
| mickey | not a mouse |
--------------------------------
| mickey mouse | is a mouse |
--------------------------------
| donald | is a duck |
--------------------------------