coderholic / django-cities

Countries and cities of the world for Django projects
MIT License
920 stars 374 forks source link

Error when importing all data #186

Closed tagmetag closed 6 years ago

tagmetag commented 6 years ago

Hello, I got this error when importing data:

File "C:\Users\User\Desktop\FeedGit\backend\cities\management\commands\cities.py", line 274, in import_country
    'continent': continents[item['continent']] if import_continents_as_fks else item['continent'],
KeyError: u'EU'

I set up all path in settings.py:

CITIES_DATA_DIR = '/var/data'
CITIES_FILES = {
    'country': {
        'filename': 'countryInfo.txt',
        'urls': [url_base + '{filename}', ],
    },
    'region': {
        'filename': 'admin1CodesASCII.txt',
        'urls': [url_base + '{filename}', ],
    },
    'subregion': {
        'filename': 'admin2Codes.txt',
        'urls': [url_base + '{filename}', ],
    },
    'city': {
        'filename': 'cities1000.txt',
        'urls': [url_base + '{filename}', ],
    },
    'hierarchy': {
        'filename': 'hierarchy.txt',
        'urls': [url_base + '{filename}', ],
    },
    'alt_name': {
        'filename': 'alternateNames.txt',
        'urls': [url_base + '{filename}', ],
    },
    'postal_code': {
        'filename': 'allCountries.txt',
        'urls': [url_base + '{filename}', ],
    }
}
CITIES_LOCALES = ['en', 'und', 'link']

This issue because when I migrate cities, it doesn;t create data about Continents. I dont know the reason Please help me!

rushil02 commented 6 years ago

Hey, I encountered the exact same error, but I'm not using any customized file settings. Why is this happening and what is the way around this?

blag commented 6 years ago

@feedgit and @rushil02

Open a Django/Python shell and run the following:

from cities.models import Continent
from cities.util import add_continents

add_continents(Continent)

Then run the import command again.