Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
5688 มุมมอง

Hi,

 _sql_constraints = [('name_uniq', ...]  for work fine in a new database[empty], but for an existing db it didn't work, is there any way to applied it to an existing db


Regards,

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Please refer to this one

https://www.odoo.com/forum/help-1/question/why-sql-constraints-not-working-39549

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Well you have to add pre_init_hook function in the __init__ to sanitize your field before applying the sql constraint.

so in the python function be sure to check if all records meet the new condition and automate fixed for those who wont comply.

Then you gonna be able to apply the constrain

อวตาร
ละทิ้ง