Odoo Help


How make field become unique / primary key

on 12/16/14, 5:27 PM 1,882 views

Hi, i want to question ...

I create field, but i want the field become unique or primary key , 

class Product (osv.osv):
    _name = 'kode.warna'
    _columns = {
                'name': fields.char('Kode Warna', required=True),
                'ket': fields.char('Nama Warna', required=True),

How field 'name' become unique or primary key ?


thanks ...

On 12/16/14, 5:39 PM

Additionally define something like:

 _sql_constraints = [ ('name_uniq', 'unique(name)', 'Two foos with the same name!') ]

or like

    _sql_constraints = [
        ('name_uniq', 'unique(name, company_id)', 'Name must be unique per Company!'),


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: 12/16/14, 5:27 PM
Seen: 1882 times
Last updated: 2/13/17, 10:55 PM