I have a new custom model defined like this
class Customer(models.Model):
_name = "my_module.customer"
_inherits = {"res.partner": "partner_id"}
partner_id = fields.Many2one(comodel_name="res.partner", ondelete="restrict", required=True)
# more fields...
I have some records in the database (customer and the linked partner). Also the partner records are also linked to portal users (res.users
)
Now, I want to remove the partner_id
field on my custom model but when i try to upgrade I get a foreign key violation error
psycopg2.errors.ForeignKeyViolation: update or delete on table "res_partner" violates foreign key constraint "res_users_partner_id_fkey" on table "res_users"
The error makes perfect sense since the res.partner
record is still referenced in res.users
. What I do not understand is why odoo is trying to delete the res.partner
record linked to my_module.customer
instead of simply unlinking and dropping the partner_id
column. Does a Many2one field field behave differently when using delegation?
Any ideas on how I would successfully remove the partner_id
field from my_module.customer
and leave res.partner
and res.users
intact?