Odoo Help


In Odoo v8 API how to define a unique field

Ron Arts
on 3/29/15, 3:11 PM 1,449 views

The old API defined a unique field as follows:

_sql_constraints = [
('cne_unique', 'unique(cne)', 'cne already exists!')

The new API deprecates this, and recommends to use @api.constrains, but how can I code to check for uniqueness in an efficient way?


Cyril Gaspard (GEM)

--Cyril Gaspard (GEM)--

| 5 6 8
Paris, France
--Cyril Gaspard (GEM)--

Forum contributor since 2008

Cyril Gaspard (GEM)
On 3/29/15, 3:26 PM


this is _constraints which is deprecated (python constraint), not _sql_constraints, see :


Ron Arts
On 3/30/15, 10:05 AM

@Cyril: please read my question. I know it is deprecated, I need to know how to do this in v8. 

please read my answer and verify in link I gave, _constraints and and _sql_constraints are two different things, you talk about _sql_constraints and this is not deprecated, see after => copy/paste v8 doc (link I gave) : _constraints list of (constraint_function, message, fields) defining Python constraints. The fields list is indicative Deprecated since version 8.0: use constrains() _sql_constraints list of (name, sql_definition, message) triples defining SQL constraints to execute when generating the backing table

Cyril Gaspard (GEM)
on 3/30/15, 4:16 PM

Cyril, I sincerely apologize. You were completely right. _sql_constraints is not deprecated. I just don't know how to read. Thanks.

Ron Arts
on 3/30/15, 4:22 PM

Now you have your answer ^^, bye

Cyril Gaspard (GEM)
on 3/30/15, 6:42 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 3/29/15, 3:11 PM
Seen: 1449 times
Last updated: 4/14/16, 3:24 AM