A note for everyone trying this and not worked at the first time check data files for duplicated data, then the data in your module, delete duplicated ones then restart the service and upgrade the module
@mrss73066 күн бұрын
how i can use it for date ?
@muthaiyanselvam40472 жыл бұрын
Hiiiiiii....Odoomates.... i'm regularly following your videos...thanks for your past & future videos........ currently i'm using the odoo14 version..... i tried this sql_constraints............not working in my system............ please advice me class HospitalToggles(models.Model): _name = "patient.toggle" _description = 'Hospital Appointment' name = fields.Char(string='Name') _sql_constraints = [('unique_toggle_name', 'unique(name)', 'name is unique......')]
@OdooMates2 жыл бұрын
May be there is existing duplicated names in the db ?
@OdooMates2 жыл бұрын
If there is already values that violates the constrains it will not work, try deleting or updating those values manually and try or try in a fresh db
@muthaiyanselvam40472 жыл бұрын
@@OdooMates you are right yes i already fixed in the fields into data files ......., now its working thanks
@futhedude48482 жыл бұрын
@@OdooMates sir, if there's none values which violates the constrains? How to resolve this?
@OdooMates2 жыл бұрын
Fix the existing data manually or use model constrains instead of sql constrains
@kenzasouabni2 жыл бұрын
after doing this it's always related by id per default not by the field that i need , why?
and the class A is like this _name = "module.A" _description = "A" _rec_name = "champ1" champ1 = fields.Integer(string="champ1", required=True) _sql_constraints = [('unique_name', 'unique(champ1)', 'champ1 must be unique !')]
@OdooMates2 жыл бұрын
@@kenzasouabni so if you enter duplicated value in the champ1 field, warning is not raised ?
@kenzasouabni2 жыл бұрын
@@OdooMates The error "NS must be unique" raised but when I want to see the tables in the command prompt, field1 of table A is correct but field1 of table dd is not the same as table A it returns me the value of the id in field1 and not the value of field1
@eventdz61822 жыл бұрын
it's not working in odoo 15
@OdooMates2 жыл бұрын
This will work in all versions, may be there is already some record that violating this constrains?
@futhedude48482 жыл бұрын
this _sql_constraints have a huge weakness that if there's already some records which have values violates the rules, then that rule is not affected. in that case, we should use @api.constrains instead. in fact, this is not good to use, i recommend to use @api.constrains instead of _sql_constraints in every posible way.
@OdooMates2 жыл бұрын
the advantages sql constrains is,it is much faster than api constrains