django-cities-light: Problem with import cities by manage.py, got error
Hello! Today i’ve got an error whe tried to import data using manage.py cities_light. i’ve got that error
[bison@mymachine backend]$ python manage.py cities_light
cities_light WARNING Assuming local download is up to date for http://download.geonames.org/export/dump/countryInfo.txt
cities_light INFO Forced import of countryInfo.txt because data do not seem to have installed successfuly yet, note that this is equivalent to --force-import-all.
cities_light INFO Importing countryInfo.txt
Traceback (most recent call last):
File "/backend/venv/lib/python3.9/site-packages/django/db/models/fields/__init__.py", line 1823, in get_prep_value
return int(value)
ValueError: invalid literal for int() with base 10: ''
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/backend/manage.py", line 22, in <module>
main()
File "/backend/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/backend/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/backend/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/backend/venv/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/backend/venv/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/backend/venv/lib/python3.9/site-packages/cities_light/management/commands/cities_light.py", line 217, in handle
self.country_import(items)
File "/backend/venv/lib/python3.9/site-packages/cities_light/management/commands/cities_light.py", line 312, in country_import
country = Country.objects.get(geoname_id=items[ICountry.geonameid])
File "/backend/venv/lib/python3.9/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/backend/venv/lib/python3.9/site-packages/django/db/models/query.py", line 424, in get
clone = self._chain() if self.query.combinator else self.filter(*args, **kwargs)
File "/backend/venv/lib/python3.9/site-packages/django/db/models/query.py", line 941, in filter
return self._filter_or_exclude(False, args, kwargs)
File "/backend/venv/lib/python3.9/site-packages/django/db/models/query.py", line 961, in _filter_or_exclude
clone._filter_or_exclude_inplace(negate, args, kwargs)
File "/backend/venv/lib/python3.9/site-packages/django/db/models/query.py", line 968, in _filter_or_exclude_inplace
self._query.add_q(Q(*args, **kwargs))
File "/backend/venv/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1393, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File "/backend/venv/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1412, in _add_q
child_clause, needed_inner = self.build_filter(
File "/backend/venv/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1347, in build_filter
condition = self.build_lookup(lookups, col, value)
File "/backend/venv/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1193, in build_lookup
lookup = lookup_class(lhs, rhs)
File "/backend/venv/lib/python3.9/site-packages/django/db/models/lookups.py", line 25, in __init__
self.rhs = self.get_prep_lookup()
File "/backend/venv/lib/python3.9/site-packages/django/db/models/lookups.py", line 77, in get_prep_lookup
return self.lhs.output_field.get_prep_value(self.rhs)
File "/backend/venv/lib/python3.9/site-packages/django/db/models/fields/__init__.py", line 1825, in get_prep_value
raise e.__class__(
ValueError: Field 'geoname_id' expected a number but got ''.
So, in the backend/venv/lib/python3.9/site-packages/cities_light/management/commands/cities_light.py after 308 line i put the code
if not items[ICountry.geonameid]:
print(ICountry.geonameid)
print(items)
it returns
16
['CS', 'SCG', '891', 'YI', 'Serbia and Montenegro', 'Belgrade', '102350', '10829175', 'EU', '.cs', 'RSD', 'Dinar', '381', '#####', '^(\\d{5})$', 'cu,hu,sq,sr', '', 'AL,HU,MK,RO,HR,BA,BG']
Could you help with that? Do you have any ideas?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 16
Hi everyone, here is a draft PR to solve this issue. https://github.com/yourlabs/django-cities-light/pull/255
Please test installing from the branch:
pip install git+https://github.com/yourlabs/django-cities-light.git@fix/import-error
She is filtering the cities to be imported only to the places from France.
I will try to provide a solution for this within the project today. And let you know
SOLVED. Apparently you have to run this. Note in this case, only France will be included. You can change the country.
CITIES_LIGHT_TRANSLATION_LANGUAGES = ['fr', 'en'] CITIES_LIGHT_INCLUDE_COUNTRIES = ['FR'] CITIES_LIGHT_INCLUDE_CITY_TYPES = ['PPL', 'PPLA', 'PPLA2', 'PPLA3', 'PPLA4', 'PPLC', 'PPLF', 'PPLG', 'PPLL', 'PPLR', 'PPLS', 'STLMT',]
It’s because they added this city or country and doesn’t have a geoname_id assigned. I suppose because is a "PCLH historical political entity. "