upgrade-sql-constraints (U1902)#
_sql_constraints, silently ignored since Odoo 19.0.
Applies to Odoo 19.0 and later.
What it does#
Reports _sql_constraints in model classes.
Why is this bad?#
Odoo 19.0 no longer reads _sql_constraints: it logs a warning and the
constraint is not created, so duplicates and invalid rows get in. Declare
each constraint as a models.Constraint attribute instead.
Example#
_sql_constraints = [
("code_uniq", "unique(code)", "The code must be unique."),
]
Use instead:
_code_uniq = models.Constraint("unique(code)", "The code must be unique.")
Fix safety#
Safe, as Odoo’s script 18.1-00-sql-constraint does it, when the list holds
only (name, definition, message) tuples with a literal name and the file
uses models.. Otherwise there is no fix.