[FIX] models: commit *before* trying to set NOT NULL constraint
Setting NOT NULL constraints on required fields may fail if there are any row with unset value for this column. The ORM handle this case by catching the exception raised and warning user. However, not commiting the current transaction before, will rollback changes made before like setting default values or renaming a column.
This commit is contained in:
parent
8a1d7dfe7b
commit
5b1beec1f2
|
@ -2585,8 +2585,8 @@ class BaseModel(object):
|
|||
self._set_default_value_on_column(cr, k, context=context)
|
||||
# add the NOT NULL constraint
|
||||
try:
|
||||
cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" SET NOT NULL' % (self._table, k), log_exceptions=False)
|
||||
cr.commit()
|
||||
cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" SET NOT NULL' % (self._table, k), log_exceptions=False)
|
||||
_schema.debug("Table '%s': column '%s': added NOT NULL constraint",
|
||||
self._table, k)
|
||||
except Exception:
|
||||
|
|
Loading…
Reference in New Issue