Odoo Help

Welcome!

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.

0

Integrity Error - creation/update: a mandatory field is not correctly set on Many2many relation

By
Nehemias Herrera
on 12/18/14, 6:26 PM 699 views

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

It would help if you specify when/how are you getting that error. When you are saving a new record? Or?

Ivan
on 12/18/14, 8:31 PM

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

Nehemias Herrera
on 12/18/14, 10:35 PM

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')

Nehemias Herrera
on 12/19/14, 7:14 AM
1

Ludo - Neobis

--Ludo - Neobis--
2387
| 2 2 5
Hoogvliet, Netherlands
--Ludo - Neobis--

Developer

Ludo - Neobis
On 12/19/14, 3:43 AM

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.

),

 

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

2 follower(s)

Stats

Asked: 12/18/14, 6:26 PM
Seen: 699 times
Last updated: 3/16/15, 8:10 AM