Odoo Help


How can I mark a field "unique" in a custom model?

on 6/26/13, 3:32 PM 10,321 views

When I create a custom model in the web GUI, how can I mark a field as "unique", so that the database will never create a second row with the same field value?


Ray Carnes

--Ray Carnes--
| 9 7 9
Keyport, United States
--Ray Carnes--

Senior ERP Analyst

OpenERP 6.1, 7.0; Odoo 8.0, 9.0, 10.0 and 11.0.

Completed Odoo Functional and Technical Training.

Functional Areas:

  • CRM/Sales

  • Inventory

  • Manufacturing

  • Accounting

  • Purchasing

Major Skills:

  • Business Process Reengineering

  • Efficiency Consulting

  • User Needs and GAP Analysis;

  • Functional and Technical Design;

  • Prototyping and Proof of Concepts;

  • Requirements Specifications;

  • Agile Implementation;

  • Data Migration;

  • Configuration & Customization (UI and code);

  • Integration - Odoo and non Odoo Applications and Services;

  • Training and Knowledge Transfer;

  • Go Live Support;

  • Helpdesk;

  • Version Upgrades and Migration.

  • Accounting Expert.

I have over 20 years of experience empowering and enabling users with enterprise information systems that make a real and measurable difference in their ability to proactively manage their businesses and organizations. 

I am a skilled Communicator and I only take the serious things seriously!

Ray Carnes
On 6/26/13, 4:42 PM

You can only do this when you create your field via Python.

See https://accounts.openerp.com/forum/Help-1/question/16386

_sql_constraints = [
                      'Choose another value - it has to be unique!')

Note that if there are existing records for the model in the database, then any field values have to be unique, or this will fail and OpenERP will do nothing to enforce the constraint for new records.

Thanks, so I will have to write a Python module for my table. Maybe it would be a nice enhancement if there would be a "unique" flag in the GUI as well. I assume, that unique fields are needed often (serial numbers, order numbers, etc.).

on 6/26/13, 7:58 PM
Thierry Godin
On 6/26/13, 4:40 PM


add a sql constraint to your model :

_sql_constraints = [
        ('uniq_name', 'unique(stuff_name)', "A stuff already exists with this name . Stuff's name must be unique!"),

Best regards

Thanks, too!

on 6/26/13, 8:00 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: 6/26/13, 3:32 PM
Seen: 10321 times
Last updated: 11/1/17, 1:12 AM