Context:
I am migrating a localization module from v16 to v18. The module loads States, Districts, and Cities.
The data is structured in a single CSV file targeting res.country.state using nested One2Many fields to create the hierarchy in one go.
The structure looks like this:
File: data/res.country.state.csv
Columns: "id","country_id","code","name","district_ids/code","district_ids/name","district_ids/city_ids/code","district_ids/city_ids/name"
The Problem: In the initial version, the CSV was loaded without an "id" column (External ID) for the States. When I update the module on an existing database (where data was already loaded), Odoo creates duplicates of the Districts and Cities.
It seems that because the Districts and Cities are defined as nested columns (district_ids/name) inside the State CSV, they do not have their own fixed External IDs (xml_id). Therefore, every time I update the module to add new cities, Odoo treats the existing nested lines as new records and duplicates them.
My Goal: I need to be able to update the module to add new cities/districts periodically without duplicating the existing ones, and without maintaining two separate versions of the module (one for fresh installs and one for updates).
Questions:
Is there a way to prevent duplication while keeping this nested CSV structure?
Should I split the CSV into 3 separate files (States, Districts, Cities) with explicit IDs? If so, how do I handle the migration for existing databases that already have the data loaded "anonymously"?
Any advice on the best migration strategy would be appreciated.