This question has been flagged

I'm on Odoo V9 trying to import 2 files, employees.csv and departments.csv. Employees has a column that references the Department's unique id (which I've mapped to the External ID per Odoo documentation). When mapping the department's unique in Departments I select "External ID" as my field and in Employees I select "Departments/External ID". When I try to validate employees.csv I get: 

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)

I'm not sure where that department_id is coming from. They are not the External IDs that I imported. I'm having this issue importing other related records as well. This was just the easiest to exemplify.

Avatar
Discard
Author Best Answer

Alright, I've figured this one out on my own too. Turns out, your unique identifier has to be unique across ALL models. So, if my departments.csv uses 1, 2, 3... as its unique id, employees.csv can't use 1, 2, 3.... I changed them to dept_1, dept_2, dept_3... and emp_1, emp_2, emp_3... and that did the trick!

Avatar
Discard