From 0a2fcfbce900e78bcee2d6047d5ec5aa793cdf46 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Thu, 17 Oct 2019 12:29:44 +0000 Subject: [PATCH] [FIX] fields: do not attempt to set foreign keys on views Users sometimes define custom models on SQL views e.g. @nseinlet In such a case, Odoo should not attempt to create foreign keys as it just cannot work on views. This could prevent the migration of a database with such a custom model using a view when it attempted to fix the missing foreign keys when updating the modules. closes odoo/odoo#38988 X-original-commit: dfaea03de57394a9a188f499da664c57dd9adc29 Signed-off-by: Denis Ledoux (dle) --- odoo/fields.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/odoo/fields.py b/odoo/fields.py index 7662a0b0031..b757beae734 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -2347,6 +2347,9 @@ class Many2one(_Relational): def update_db_foreign_key(self, model, column): comodel = model.env[self.comodel_name] + # foreign keys do not work on views, and users can define custom models on sql views. + if not model._is_an_ordinary_table() or not comodel._is_an_ordinary_table(): + return # ir_actions is inherited, so foreign key doesn't work on it if not comodel._auto or comodel._table == 'ir_actions': return