1
votes

This is more of a public service announcement than a question:

I was just implementing a pretty big data model in OpenERP 6.1 and had the problem that some object references were defined before the objects they reference. A simple solution for this is to define stubs of these objects containing nothing more than the "_name" attribute and "overwrite" these stubs with the actual object definition later on. The interesting thing is, this problem only seems to arise with many2one and one2many relations. At first many2many relations seem to be unaffected by this behaviour, even though they should. Turns out they still are, but differently.

It seems, that the database table of the target object of the many2many relation will be created in addition to the mapping table, if it is not available already. When the target objects definition is then read later on, its fields will be added to the then already created database table. So far, so good. The problem is that during the creation of the target objects database table the ID field is omitted. Since OpenERPs database update routines seem to not touch any "supposed to be there" stuff, this field will never be added to the table. This results in error messages, telling you e.g. that openerp is not able to add a foreign_key reference on a table, which should reference the supposed to be there ID field of the target object.

TL;DR: Always create stubs for all your object definitions, if those objects are referenced before their actual definitions. Else you will be haunted by this: ProgrammingError: there is no primary key for referenced table ...

1
something like you are referring a table before defined paste ur full module code here so that it will be easy to tracebackSenthilnathan
Thank you for your effort, but this wasn't a question. ;) I know what the problem is and how to avoid it. If you want to reproduce the behaviour to see it yourself, then all neccessary information is available in my post. Since google wasn't able to provide any useful information when using the above error message as search string, I thought I might leave some helpful description of the problem here, so the next unfortunate soul might immediately know what's wrong.asdfsdfsdfsdfsd3232

1 Answers

0
votes

yes, this is a well known issue with openerp's older version v6 and v6.1, which seems now no longer with v7. This issue arises because of cyclic dependency where you have ref. of Object A on Object B which has Ref. of Object C which has dependency on Object A.

To avoid this scenario, better to refactor object dependencies, even after that issue still exist, then you can create an initial declaration of tables which only contains it's name, and NO _column. Let this file get loaded first and after that your other objects can follow.