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

1 投票
2 回答
6970 浏览
提问于 2025-04-18 06:25

我创建了三个类,比如 ali_khan 这个类有一个 ID('ali_ids':fields.one2many('ali.khan', 'chbc_id', 'Ali khan')),还有 test_chbc 和 test_destitute。我在另外两个类中引用了这个 ID。我可以在 test_chbc 中添加和删除记录,但每次我尝试在 test_destitute 中添加记录时,都会出现完整性错误。

我的代码:

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

这个错误发生是因为你没有给必填的字段指定一个值。

你可以试着升级你的模块,然后确保在chbc_id这个字段里输入一个有效且存在的值。

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”这个词。

撰写回答