Odoo Help


See the SQL constraints section for further details?

on 4/10/13, 5:46 PM 4,798 views

Can somebody point me to this section? I can't find it... If not, how do I get my models loaded when they all reference each other? Can I use _sql to add constraints to all tables from the last model to be loaded?



| 2 2 4
Buenos Aires, Argentina

Python developer, big fan of sailing

On 4/10/13, 5:50 PM

Check the models you are updating, they have a SQL section in the model definition. You can check it in the source code

The source code is the only worthwhile documentation I've found so far. I am trying to find examples on usage of the _sql predefined field but cannot locate it in any sources.

on 4/11/13, 10:09 AM
Nicolas C
On 4/11/13, 7:00 PM


Not sure that adding SQL constrain is the right way to do. OpenERP deal with it's own constraints at the Controller layer (MCV architecture). If I correctly understand OpenERP doc I saw time's ago; model definitions, constraints, ... are "OpenERP" object which are stored in pgSQL but... many constraints are not simply "translated" as SQL constraints, theses are simply defined within the python code of OpenERP (ie: should not be empty, must be valid EAN13, ...).

Even if I understand "native SQL" could be easier/faster, OpenERP is not "just a pgSQL DB", this in an ERP and I feel more comfortable to use the XML RPC layer and left the controller do his job (ie: If I forget something he will tell me, and if some table should be updated, it will do it by itslef).

Here is my kind opinion. Hope this will help you to select the better/safer technical solution for your project.

If you want to dig a bit wihtin the OpenERP "model", you could have a look to the "settings/parameters/structure of the DB/model" and look at the ir.model and ir.model.fields. Here are all the models/fields definitions used by OpenERP (ie: you could filter on many2many field type).

Have a nice day. @++ Nicolas

Thanks Nicolas, I'm not a big fan of ORM and the OpenERP one is at times confounding to me due to it's entity identity handling. I prefer a little more control but keep resisting the urge to bypass ORM and cursor execute my own queries. Have a nice day too!

on 4/12/13, 9:40 AM

I think I have chosen the safer solution now. It is also much faster than refactoring my code only to run into the same errors again and again. I have models V m2m C, C m2m D, C o2m N, D m2o E and they work fine except from the level of V where it all blows up. Uncaught exceptions within ORM module only, not my models. At most this is a query with 3 joins so now I am putting that query into a view and building model from the view. My class diagrams are valid but ORM just cannot handle it. It creates intersect tables with no constraints - bad referential integrity that....

on 5/1/13, 2:41 PM

@mike what do you mean by "putting that query into a view and building model from the view.." , can you be more specific?

Group ODOO
on 8/18/13, 6:39 AM

Instead of using a table in postgres use a view - http://www.postgresql.org/docs/8.3/static/sql-createview.html and then build your model against that view as though it were a table. The model must have _auto = False to prevent OpenERP from creating a new table.

on 8/20/13, 9:40 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

0 follower(s)


Asked: 4/10/13, 5:46 PM
Seen: 4798 times
Last updated: 3/16/15, 8:10 AM