Odoo Help


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 2,112 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

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/18/14, 8:08 AM
Seen: 2112 times
Last updated: 8/21/17, 12:57 AM