Odoo Help
Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM
|
e-Commerce
|
Accounting
|
Inventory
|
PoS
|
Project management
|
MRP
|
etc.
Integrity Error - creation/update: a mandatory field is not correctly set on Many2many relation
I am getting this error when trying to save a new record of the Estudiantes model, I am able to save if the carrera_ids field is empty but if I add one Carrera to it then I get the error
Integrity Error
The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set
[object with reference: uccart.carreras - uccart.carreras]
These are my models
class Carreras (models.Model):
_name = 'uccart.carreras'name = fields.Char(string="Carrera")
codigo = fields.Char(string="Código")estudiante_ids = fields.Many2many('uccart.estudiantes','uccart_carreras_estudiantes','estudiante','carrera')
class Carreras_Estudiantes(models.Model):
_name = 'uccart.carreras.estudiantes'
carrera = fields.Many2one('uccart.carreras')
estudiante = fields.Many2one('uccart.estudiantes')class Estudiantes (models.Model):
_name = 'uccart.estudiantes'
_inherits = {'res.partner':'partner_id'}carrera_ids = fields.Many2many('uccart.carreras','uccart_carreras_estudiantes','carrera','estudiante')
I have made other Many2many relationships before in tha same way, don't know what the error is, help is much appreciated
I think your field definition is missing a parameter. This is an example for the existing account module:
'move_ids': fields.many2many(
'account.move', <-- the object to refer to
'account_bank_statement_line_move_rel', <-- The name of the relational table in the database
'statement_line_id', <-- The id on the object you are currently on
'move_id', <-- the id of the object on the other side (account.move in this case)
'Moves' <-- the name of the field on your model for viewing purposes.
),
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.
RegisterOdoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.
Test it nowQuestion tools
Stats
Asked: 12/18/14, 6:26 PM |
Seen: 986 times |
Last updated: 3/16/15, 8:10 AM |
It would help if you specify when/how are you getting that error. When you are saving a new record? Or?
I am getting this error when trying to save a new record of the Estudiantes model, I am able to save if the carrera_ids field is empty but if I add one Carrera to it then I get the error
Ludo's answer help me solve it, the problem was I had the id of the current object and the other model's id reversed, all I had to do was change the Many2many definition to fields.Many2many('uccart.carreras','uccart_carreras_estudiantes','estudiante','carrera')