class PassportManagementModels(models.Model):
_name = 'om_hrm.passport'
_description = 'Passport Master'
_inherit = ['mail.thread']
_rec_name = "PassportNo"
PassportNo = fields.Char(string='Passport Number',size=16,required=True) PassportIssueDate = fields.Date(string='Passport Issue Date', required=True) PassportExpiryDate =fields.Date(string="Expiry Date",required=True) PassportNationality =fields.Char(string="Nationality",size=20,required=True) Passportdob = fields.Date(string="Date of Birth",required=True) Passportholdername = fields.Char(string="Holder Full Name",required=True) Passportpossesionwith = fields.Selection([("admin","Admin"),("staff","Staff"),("other","Other")],string="Possesion With!") passport_doc_ids = fields.Many2many('ir.attachment',string='Passport Documents',ondelete='cascade')
_sql_constraints = [('passport_unique','UNIQUE(PassportNo)','The Passport Number must be unique.')].
Hello Odoo Community,
I'm currently facing an issue with a custom module in Odoo where I am trying to enforce a unique constraint on the PassportNo field in my om_hrm.passport model. Despite my efforts, the constraint does not seem to be applied correctly, even when the table is empty.
I tried below but its not working .
- Uninstalled custom module and reinstalled.
- Created new Database and installed.
- Passport table is empty and their is no data in it.
i dont know why its not effecting i get below error in CLI.
2024-09-22 18:06:53,948 90489 WARNING odoodemo1 odoo.schema: Table 'om_hrm_passport': unable to add constraint 'om_hrm_passport_passport_unique' as UNIQUE(PassportNo)
2024-09-22 18:06:54,009 90489 ERROR odoodemo1 odoo.schema: Table 'om_hrm_passport': unable to add constraint 'om_hrm_passport_passport_unique' as UNIQUE(PassportNo)
I would appreciate any insights or suggestions on how to resolve this issue. Is there something I may have overlooked in the setup of my module? Any help would be greatly appreciated!