我有一个 many2one
类型的字段。我的数据库中也有很多记录。
所以现在我想将此字段的类型从 many2one
更改为 many2many
,但是当我创建记录时,它向我显示完整性错误
.
这是我的领域:
bed_id = fields.Many2one('i.bed', 'bed', required=True, ondelete="restrict", track_visibility="onchange")
我将其更改为:
bed_id = fields.Many2many('i.bed', 'bed', required=True,string="beds", track_visibility="onchange")
完整性错误是:
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]
如何在不删除数据库中现有记录的情况下解决此问题?
最佳答案
我会将新 (many2many) 字段的名称更改为 bed_ids
。
首先这是为了Odoo指南,其次我不认为Odoo可以将字段从many2one迁移到many2many,因为在数据库方面它是一个完全不同的关系。 Many2one字段只是其他表的外键,但many2many字段是通过关联表实现的。
这就是为什么我会让旧字段存在,这样你就可以自己迁移它。迁移后,您应该删除该字段,或者让 Odoo 通过在代码中删除该字段来删除该字段。
关于python - odoo Many2one 和 Many2many,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54593931/