在OpenERP7中,核心模块account
有account.invoice
的声明,在某些时候,它有以下声明:
附加元件/帐户/ account_invoice.py:343
_sql_constraints = [
('number_uniq', 'unique(number, company_id, journal_id, type)', 'Invoice Number must be unique per Company!'),
]
在重新定义account.invoice
的模块中,我想用两种不同的方法删除约束:
在 init 中删除它(account_invoice :: init(self,pool,cr))
def __init__(self, pool, cr):
super(account_invoice, self).__init__(pool, cr)
try:
cr.execute('ALTER TABLE account_invoice DROP CONSTRAINT IF EXISTS account_invoice_number_uniq')
finally:
pass
更换约束
_sql_constraints = [
('number_uniq', 'check(1=1)', 'Dummy check, always true, used to replace the previous constraint'),
]
然而,当我重新安装发出这两个声明的模块时,我收到一个错误(在PG日志中),告诉我约束account_invoice_number_uniq
不能被用于唯一键,因为那里有#39重复的数据。
如何防止出现此类错误?如何阻止系统尝试创建(首先;然后...替换/删除)约束?
答案 0 :(得分:0)
检查下面的参考链接以删除Odoo中的父类的SQL约束
Click To See the Reference For Remove the SQL Constraint In Odoo(formally OpenERP)