我在Odoo V9上试图导入2个文件,employees.csv和departments.csv。员工有一个列引用了部门的唯一ID(我已将其映射到每个Odoo文档的外部ID)。在部门中映射部门的唯一部分时,我选择“外部ID”作为我的字段,在员工中选择“部门/外部ID”。当我尝试验证employees.csv时,我得到:
insert or update on table "hr_employee" violates foreign key constraint "hr_employee_department_id_fkey" DETAIL: Key (department_id)=(1470) is not present in table "hr_department". at row 18 (3 more)
insert or update on table "hr_employee" violates foreign key constraint "hr_employee_department_id_fkey" DETAIL: Key (department_id)=(1471) is not present in table "hr_department". at row 30 (7 more)
insert or update on table "hr_employee" violates foreign key constraint "hr_employee_department_id_fkey" DETAIL: Key (department_id)=(1473) is not present in table "hr_department". at row 32 (15 more)
insert or update on table "hr_employee" violates foreign key constraint "hr_employee_department_id_fkey" DETAIL: Key (department_id)=(1472) is not present in table "hr_department". at row 392 (8 more)
insert or update on table "hr_employee" violates foreign key constraint "hr_employee_department_id_fkey" DETAIL: Key (department_id)=(1475) is not present in table "hr_department". at row 405 (1 more)
我不确定department_id的来源。它们不是我导入的外部ID。我也有这个问题导入其他相关记录。这只是最容易举例说明的内容。
编辑:我可能已经想出了什么。每个唯一ID在所有文件中都应该是唯一的,而不仅仅是当前文件。而不是1,2,3 ...我已经将它们改为dept_1,dept_2,dept_3 ......我仍然无法测试我的理论,因为我遇到了另一个错误:
Missing required value for the field 'First' (name) at row 5
即使它认为缺少的行中有值。
答案 0 :(得分:0)
事实上,事实证明,您的唯一标识符必须在所有模型中都是唯一的。因此,如果我的departments.csv使用1,2,3 ......作为其唯一ID,则employees.csv不能使用1,2,3 ....我将它们更改为dept_1,dept_2,dept_3 .. 。和emp_1,emp_2,emp_3 ......这就是诀窍!