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.


Remove _sql_constraints

Sudhir Arya (SA)
on 3/11/13, 6:42 AM 6,309 views

I want to remove _sql_constraints (database level).

For example in account_invoice.py there is a constraints on number field. Now I want to remove it.

Can anyone have idea how to deal with this?

Thank you.


Andreas Brueckl

--Andreas Brueckl--
| 7 8 7
Vienna, Austria
--Andreas Brueckl--
OpenERP Consulting and Development
Andreas Brueckl
On 3/11/13, 6:50 AM

With the following steps I was able to remove SQL constraints in version 6.0 (but it should also work for v7.0):

  1. Remove SQL constraint in Python code
  2. Manually remove the constraint in PostgreSQL using PgAdmin3

If you do not want to change the existing module, you can

  • Create a new module and
  • replace the SQL constraint with the value CHECK(1=1)

In your example you can create a new module and write:

class account_invoice(osv.osv):
    _inherit = "account.invoice"
    _sql_constraints = [
    ('number_uniq', 'Check(1=1)', 'Invoice Number must be unique per Company!'),

Hello @Andreas Brueckl, If I have something like this: _sql_constraints = [ ('name_company_uniq', 'unique(name, company_id)', 'Tax Name must be unique per company!'), ] But I just want to remove the unique from name, do you know how should I do it ? To keep the company and remove the name from being unique ?


Versão Integral, Anabela Damas
on 1/29/14, 9:23 AM

Just keep the name 'name_company_uniq' and replace the logic with 'unique(company_id)'.

Andreas Brueckl
on 2/3/14, 4:46 AM

That is the way I try, but I have always an error in log, so I found an workaround. But thanks.

Versão Integral, Anabela Damas
on 2/3/14, 7:54 AM

ca marche pas avec moi "check(1=1)"

fadhel salhi
on 3/29/14, 5:05 PM

Francesco OpenCode

--Francesco OpenCode--
| 5 7 9
Grottaglie, Italy
--Francesco OpenCode--

Italian Odoo (OpenERP) Modules Developer LINKEDIN: http://www.linkedin.com/in/francescoapruzzese

Francesco OpenCode
On 3/11/13, 6:52 AM

Create you personal module. Inherith the account invoice class and set the _sql_constraints to null.

This is an example that I use to change the sale order _sql_constraints

class sale_order(osv.osv):

    _name = "sale.order"
    _inherit = "sale.order"

    _sql_constraints = [('name_uniq', 'unique(name, date_order)', 'Order Reference must be unique per Date!'),]


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: 3/11/13, 6:42 AM
Seen: 6309 times
Last updated: 7/22/16, 9:39 AM