Odoo Help


This community 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.


Is it possible to add multiple sql constraint in a same model need help................This code is works or not?

on 6/18/14, 8:08 AM 1,065 views

class scheme_type_info(osv.osv):
              'scheme_id':fields.integer('Scheme Type',required=True,size=50),
              'interval':fields.integer('Start Days',required=True,size=64,help="set the number of start date interval"),
              'interval1':fields.integer('End Days',required=True,size=64,help="set the number of end date interval"),
              'criteria':fields.integer('Number of Tickets',required=True),
    _sql_constraints=[('unique_scheme_id','unique(scheme_id)','Error! scheme Id Already Exist')]

    _sql_constraints=[('unique_interval','unique(interval)','Error! Start Day Already Exist')]
    _sql_constraints=[('unique_interval1','unique(interval1)','Error! End Day Already Exist')]

Jaakko Komulainen
On 6/18/14, 8:19 AM

_sql_constraints is a list so you can add them like: 

_sql_constraints =[('unique_scheme_id','unique(scheme_id)','Error! scheme Id Already Exist'), ('unique_interval','unique(interval)','Error! Start Day Already Exist'),('unique_interval1','unique(interval1)','Error! End Day Already Exist')]


Ruchir Shukla
On 6/18/14, 8:20 AM

Try this : It will work

_sql_constraints = [('unique_scheme_id','unique(scheme_id)','Error! scheme Id Already Exist'),

                                       ('unique_interval','unique(interval)','Error! Start Day Already Exist')]



René Schuster

--René Schuster--
| 5 5 8
Weinheim, Germany
--René Schuster--

Challenge Everything!

René Schuster
On 6/18/14, 8:25 AM

I'm not sure how your code will perform, either throw an error, or just use the last constraint.

But what you want is easy to achieve:

sql_constraints is a list of tuples: So add all your constraints into one list:

_sql_constraints = [
    ('unique_scheme_id', 'unique(scheme_id)', 'Error! scheme Id Already Exist'),
    ('unique_interval', 'unique(interval)', 'Error! Start Day Already Exist'),
    ('unique_interval1', 'unique(interval1)', 'Error! End Day Already Exist')

Note: It might be possible that you want the combination of those three fields to be unique. In that case, use only one unique statement with all fields as argument:

_sql_constraints = [('unique_sheme_type', 'unique(scheme_id,interval,interval1), 'Error! This Type already exists!')]



Hi, This time only two constraints is taken not excecute 'unique_interval1', 'unique(interval1)', 'Error! End Day Already Exist') this constraints fields

on 6/19/14, 5:14 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 6/18/14, 8:08 AM
Seen: 1065 times
Last updated: 3/16/15, 8:10 AM