1
votes

I have a field of type many2one. Also in my database I have many records.

So right now I want to change the type of this field from many2one to many2many, but when I create a record it shows me an Integrity Error.

This is my field:

bed_id = fields.Many2one('i.bed', 'bed', required=True, ondelete="restrict",  track_visibility="onchange")

And I was change it to this:

bed_id = fields.Many2many('i.bed', 'bed', required=True,string="beds",  track_visibility="onchange")  

The Integrity Error is:

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: bed_id - bed.id]

How can I fix that without deleting the existing records in my database?

1

1 Answers

2
votes

I would change the name of the new (many2many) field to bed_ids.

Firstly it is for the sake of Odoo guidelines and secondly i don't think Odoo can migrate a field from many2one to many2many, because on database side it is a complete other relation. Many2one fields are just foreign keys to other tables, but many2many fields are realised by an associative table.

That's why i would let the old field just exist, so you can migrate it yourself. After migration you should remove the field or let Odoo remove the field, by deleting it in your code.