I have a custom module in odoo 9. In the model, I have animals and cages.
In a cage can be more than one animal. An animal can be only in one cage.
That is my model:
class Animal(osv.osv):
_name = 'Animal'
_columns = {
'name': fields.char('Animal Name', size=2048),
'cage_id': fields.many2one('cage', required=True, ondelete='cascade', string="Cage"),
}
class Cage(osv.osv):
_name = 'Cage'
_columns = {
'name': fields.char('Cage Name', size=100),
'animals': fields.one2many('Animal', 'cage_id', string="Animals"),
}
When I install the module, everything works fine. But if I try to uninstall it, the table "Animal" remains in the database and there is an error in the console:
2016-10-31 16:37:21,091 28082 INFO myserver openerp.addons.base.ir.ir_model: Unable to delete 7565@ir.model.fields
Traceback (most recent call last):
File "/etc/odoo/server/openerp/addons/base/ir/ir_model.py", line 1269, in unlink_if_refcount
self.pool[model].unlink(cr, uid, [res_id], context=context)
File "/etc/odoo/server/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/etc/odoo/server/openerp/addons/base/ir/ir_model.py", line 461, in unlink
self.browse(cr, user, ids, context=context)._prepare_update()
File "/etc/odoo/server/openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs)
File "/etc/odoo/server/openerp/addons/base/ir/ir_model.py", line 449, in _prepare_update
raise UserError(msg % (field, model._field_inverses[field][0]))
UserError: (u"The field 'animal.cage_id' cannot be removed because the field 'cage.passwords' depends on it.", None)
I have reviewed the official documentation, but I am not able to locate the error.
What is wrong in the model?