Unique Sql Constraints in Odoo

Hello Odooers, Odoogig and Odoo Lovers,

In this Odoo Tips Tutorial, I would like to explain how to use Unique _sql_constraints in Odoo

  • SQL constraints will add to the table definition into database and implemented by PostgreSQL. it will be define using the class _sql_constraints attribute in odoo
  • In general term Constrain means force to follow some particular action
  • In odoo we use constrain to put some kind of restriction on record.
  • For example, an employee’s identification number must be unique, means two employee can not have a same identification number
  • So putting this type of unique restriction on records, we can use SQL Unique Constrain in odoo
  • SQL is nothing but a database which is used by odoo
  • SQL Unique Constrain will be written into python file as shown in below. it is a list of tuples with constraints name and error message.
#_sql_constraints  #Modelconstraints #odooconstraints #odoo12.0

how to write _sql_constraints in odoo 

Example

  •  So now if you try to enter identification number which is already assigned to other employee then system will restrict you with error message. See below screen
Unique sql_constrain in odoo
Unique sql_constrain in odoo


GET IN TOUCH.!

We’d Love to Hear from You! We are happy to answer any questions, you have regarding My Training.

Mail : getodootraining@gmail.com

Skype : mayur_maheshwari1

What’s app : +919924542042

1 thought on “Unique sql constraints in Odoo

LEAVE A REPLY

Leave a Reply

Your email address will not be published. Required fields are marked *