[FIX] orm: do not drop foreign keys of transient models
During the update of a module, the existing foreign keys are dropped if they have a different ondelete_rule than the one specified on the field. The foreign keys for many2one transiant -> non-transiant are created with cascade rule by default (see `m2o_add_foreign_key_checked` method) so the check needs to be realised in the same conditions.
This commit is contained in:
parent
42680c9906
commit
32f5168974
|
@ -3016,6 +3016,9 @@ class BaseModel(object):
|
|||
if len(constraints) == 1:
|
||||
# Is it the right constraint?
|
||||
cons, = constraints
|
||||
if self.is_transient() and not dest_model.is_transient():
|
||||
# transient foreign keys are added as cascade by default
|
||||
ondelete = ondelete or 'cascade'
|
||||
if cons['ondelete_rule'] != POSTGRES_CONFDELTYPES.get((ondelete or 'set null').upper(), 'a')\
|
||||
or cons['foreign_table'] != dest_model._table:
|
||||
# Wrong FK: drop it and recreate
|
||||
|
|
Loading…
Reference in New Issue