Odoo Help


Why Odoo use Create Unique Index in some model in base module?

on 6/24/14, 1:13 PM 2,078 views

I see in base module some model write this

def _auto_init(self, cr, context=None):

        super(ir_actions_act_window_view, self)._auto_init(cr, context)

        cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = \'act_window_view_unique_mode_per_action\'')

        if not cr.fetchone():

            cr.execute('CREATE UNIQUE INDEX act_window_view_unique_mode_per_action ON ir_act_window_view (act_window_id, view_mode)')


I wanna know why odoo create unique index for this model?

what is situation we can use it? Is that situable for model has 10 records, 100k records, 500k records and model have data increase dailly about 1k - 5k records per day.

My code to  check unique column of table but irgore case sensitive. Is that the right way to do that? Do we will apply this for all model have this contraints? 


_sql_constraints = [
        ('name_unique', 'unique(name)', 'Name must be unique!'),
        ('code_unique', 'unique(code)', 'Code must be unique!'),

    def _auto_init(self, cr, context=None):
        super(vhr_head_office, self)._auto_init(cr, context)
        # Use unique index to implement unique constraint on the lowercase name (not possible using a constraint)
        cr.execute("SELECT indexname FROM pg_indexes WHERE indexname = 'vhr_head_office_name_unique_index'")
        if not cr.fetchone():
            cr.execute("""CREATE UNIQUE INDEX "vhr_head_office_name_unique_index" ON vhr_head_office


Finally what is problem when we indexing a lot of model?


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/24/14, 1:13 PM
Seen: 2078 times
Last updated: 3/16/15, 8:10 AM