完整性错误。操作无法完成,可能是由于以下原因:

时间:2014-05-13 14:51:44

标签: python openerp

我创建了三个类,例如带有id的ali_khan(&#39; ali_ids&#39 ;: fields.one2many(&#39; ali.khan&#39;,&#39; chbc_id&#39;,&#39; ; Ali khan&#39;),test_chbc和test_destitute。我在其余两个类中引用了该id。我可以添加和删除记录到tes_chbc但是每次我尝试向test_destitute添加记录时都会出现完整性错误.. < / p>

我的代码:

class test_chbc(osv.osv):
    _name="test.chbc"
    _columns={
              'ali_ids':fields.one2many('ali.khan', 'chbc_id', 'Ali khan'),
              'first_name':fields.char('First Name',size=64),
              'family_name':fields.char('Family Name',size=64),
              'no_id':fields.boolean('No ID'),
              'id_num':fields.char('ID Number',size=64), #with a lable of ID Number yes/no
              'sex':fields.selection(gender_lov,'Sex',size=64),
              'date_o_birth':fields.date('Date of birth',size=64),
}    
test_chbc()

class test_destitute(osv.osv):
    _name="test.destitute"
    _columns={
              'ali_ids':fields.one2many('ali.khan', 'destitute_ids', 'Khan'),
              'first_name':fields.char('First Name',size=64),
              'family_name':fields.char('Family Name',size=64),
              'id_num':fields.char('ID Number',size=64), #with a lable of ID Number yes/no
              'sex':fields.selection(gender_lov,'Sex',size=64),
              'date_o_birth':fields.date('Date of birth',size=64),
              'formal_edu':fields.char('Formul Education',size=64),


    }
 test_destitute()

class ali_khan(osv.osv):
    _name="ali.khan"
    _description="Does any member of the household have regular paid employment"
    _columns={
              'destitute_ids':fields.many2one('test.destitute',reuired=True),
              'chbc_id':fields.many2one('test.chbc', required=True),    
              'person_name':fields.char('Name of Person'),
              'work_type':fields.char('Type of work'),
              'income_monthly':fields.char('Monthly Income'),
              'com_confirm':fields.char('Communal Confirmation'),
    }
 ali_khan()

错误:

  

操作无法完成,可能是由于以下原因: -   删除:您可能正在尝试删除其他记录时的记录   仍然引用它 - 创建/更新:强制字段不是   正确设定。 [参考对象:chbc_id-chbc.id]

注意:

  

如何设置many2fields的默认值,例如chbc_id和destitute_ids

2 个答案:

答案 0 :(得分:0)

如果未指定必填字段的值

,则会发生此错误

判断尝试升级模块,然后确保在字段chbc_id中输入有效和现有值。

答案 1 :(得分:0)

class ali_khan(osv.osv):
    _name="ali.khan"
    _description="Does any member of the household have regular paid employment"
    _columns={
              'destitute_ids':fields.many2one('test.destitute',required=True),
              'chbc_id':fields.many2one('test.chbc', required=True),    
              'person_name':fields.char('Name of Person'),
              'work_type':fields.char('Type of work'),
              'income_monthly':fields.char('Monthly Income'),
              'com_confirm':fields.char('Communal Confirmation'),
    }

我认为你错过了chbc_id字段中拼写为“required”的内容