Convert postal_codes.code to primary_key #29

wants to merge 1 commit into


None yet
3 participants

hcNick commented Feb 21, 2012

If you run the import script again after you have imported all postcodes, all the primary keys could end up referencing different postcodes. Postcodes are a unique property and should therefore be the unique identifier in any postcode table.



coderholic commented Feb 21, 2012

Why not just add a unique index?

hcNick commented Feb 21, 2012

The issue isn't an index, it's that every time you re-import the postcodes the id and postcode might match up differently. For example last time round I had GB postcode "SW20 8SF" with a primary key of 707662. Next import round, primary key 707662 pointed at TN1 6EG or something. If you assign postcodes by ForeignKey you would want them to stay the same surely?


coderholic commented Feb 21, 2012

The cities will also have different primary keys if you reimport them. Are you saying you sometimes reimport just the postcodes?


Qarterd commented Feb 22, 2012

Yeah I see the problem, geonames provides a unique id for all the other data types, we use that for the primary key so it's the same every time. The postal codes don't come with a unique id, as ItsNotWorking said that's probably because geonames is using the postal code itself as the primary key.

The problem happens if you wipe your table and re-import instead of doing an update. When updating there's code in there to find existing rows by postal code, so any matching entry is overwritten and the primary key doesn't change.

Your code fix is not quite enough, a few lines in the importer need to be changed as well.


coderholic commented Feb 22, 2012

I've pulled Kometes change, so this is now fixed in master

@coderholic coderholic closed this Feb 22, 2012

hcNick commented Feb 27, 2012

Brilliant thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment