Comment 7 for bug 393858

Revision history for this message
Nicolas DS (zyphos) wrote :

To resolve the duplicate record problem:

According to the patch 'ir_model_data_unique_constraint_error.diff'
you should edit the second duplicate record,
and add '_<id>' to 'name' field, with <id> = thisRow. 'res_id' field

ie in my case for "field_ir_actions_type":
id | module | res_id | name
238 | base | 90 | field_ir_actions_type
337 | base | 180 | field_ir_actions_type

You must modify the second one (id=337)
should become:
id | module | res_id | name
238 | base | 90 | field_ir_actions_type
337 | base | 180 | field_ir_actions_type_180

You could use this query to make it automatic:

update ir_model_data set name=name||'_'||res_id where id in (select max(id) from ir_model_data group by name,module having count(1)>1)

After that, the constraint could be apply.

ALTER table ir_model_data ADD CONSTRAINT ir_model_data_module_name_uniq unique(name, module)