Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
Hi guyz, I am learning about optional parameter regarding fields for ondelete parameter. These are the predefined values: "cascade", "set null", "restrict", "no action", "set default" Can anyone tell me when these values are set at what scenario and give me example for each predefined values in detail. For eg: "restrict" - 'journal_id': fields.many2one('account.analytic.journal', 'Analytic Journal', required=True, ondelete='restrict', select=True), - journal values must not be changed.
Foreign Key constraint on delete records in your object. These parameters define constraint on PostgreSQL level.
Restricting and cascading deletes are the two most common options.
RESTRICT prevents deletion of a referenced row.
NO ACTION means that if any referencing rows still exist when the constraint is checked, an error is raised; this is the default behavior if you do not specify anything. (The essential difference between these two choices is that
NO ACTION allows the check to be deferred until later in the transaction, whereas
RESTRICT does not.)
CASCADE specifies that when a referenced row is deleted, row(s) referencing it should be automatically deleted as well. There are two other options:
SET NULL and
SET DEFAULT. These cause the referencing columns to be set to nulls or default values, respectively, when the referenced row is deleted. Note that these do not excuse you from observing any constraints. For example, if an action specifies
SET DEFAULT but the default value would not satisfy the foreign key, the operation will fail.
About This Community
This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 5/31/13, 4:08 AM|
|Seen: 10325 times|
|Last updated: 6/27/16, 1:04 AM|