Odoo Help

Welcome!

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.

1

sql constraint is not working for a model..Why pls check .need a help

By
Odoo
on 7/22/14, 12:48 PM 1,669 views

class product_info(osv.osv):
    
    _name='product.info'
    
    
    _columns={
           'id':fields.integer('ID'),
            'product_id':fields.many2one('product.product','Name',required=True),
         'prod_category':fields.many2one('product.category','category'),
            'valid_from':fields.date('Valid From'),
            'valid_to':fields.date('Valid to'),
            
              }
    
    _sql_constraints=[('unique_product_id','unique(product_id)','Error! Product Name Already Exist!')]

2
Nhomar Hernandez
On 7/22/14, 1:04 PM

Can you share the log of your server, frequently there is a warning if the data base already exist that inform you yo must create the sql constraint manually, due to some records doesn't comply the constriant.

Yes, I would check this also. SQL constraints only work if ALL of the existing data in PostgreSQL satisfy the constraint. if you install your module and any data DOES NOT satisfy the constraint, it will fail.

Bista Solutions US, Ray Carnes
on 7/22/14, 7:14 PM
0
Krupesh Laiya
On 12/19/15, 1:29 AM

You can teke reference from the sales_team module for the same

    _sql_constraints = [

('code_uniq', 'unique (code)', 'The code of the sales team must be unique !')

]

or you can refer this link Constraints Help

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)

Stats

Asked: 7/22/14, 12:48 PM
Seen: 1669 times
Last updated: 12/19/15, 1:29 AM