我在 OpenERP/PostgreSQL 中有一个包含以下列的表:name
和description
.
我为唯一名称添加了以下验证:
_sql_constraints = [('unique_name', 'unique(name)', 'A record with the same name already exists.')]
它工作正常,但区分大小写。目前,它接受“Mickey”、“MICKEY”和“mickey”等值:
Wrong Way:
--------------------------
| name | description |
--------------------------
| mickey | not a mouse |
--------------------------
| MICKEY | not a mouse |
--------------------------
| Mickey | not a mouse |
--------------------------
有没有办法修改验证码,使其不允许用户添加多个值,例如“Mickey”、“MICKEY”和“mickey”?如何使唯一密钥验证不区分大小写?
Right Way:
--------------------------------
| name | description |
--------------------------------
| mickey | not a mouse |
--------------------------------
| mickey mouse | is a mouse |
--------------------------------
| donald | is a duck |
--------------------------------