Good evening all, following my application development, I have reached to the stage where I am about to add some data using data migrations. I did download some data from OSM (saved as json), added a load data function but when i run the migrate command I get a keyerror in my migration files:
File "/home/qgislinuxadmin/nearbyshops/shops/migrations/0002_auto_20210618_2102.py", line 18, in load_data for obj in objects['elements']: KeyError: 'elements' which would mean that the key in not in a dictionary. Any help or advice would be appreciated Kind Regards Stathis On Tuesday, June 15, 2021 at 12:01:19 PM UTC+1 Stathis Angelou wrote: > > Good morning Both and thank you very much for your help, > > Yes that worked!!? > Thank you again, > off for the next step!! > > Kind Regards > > Stathis > > On Tuesday, June 15, 2021 at 10:05:16 AM UTC+1 Nikeet NA wrote: > >> Your app is not registered in settings file as stated by Aritra. >> >> On Tuesday, 15 June 2021 at 14:22:45 UTC+5:30 arit...@gmail.com wrote: >> >>> Hello, >>> Register your app in setting.py-> INSTALLED_APPS like >>> 'appname.apps.appnameConfig' from your apps.py. Alternatively, you can >>> write 'app_name' instead of the whole sentence. >>> >>> Regards, >>> Aritra. >>> >>> On Tue, 15 Jun 2021 at 05:46, Stathis Angelou <staka...@gmail.com> >>> wrote: >>> >>>> good evening all, >>>> >>>> I have started building a webapp using python, django and linux, but >>>> i'm afraid the app does not appear under admin tab in >>>> 127.0.0.1:8000/admin >>>> I am sure I am missing something, attached is my code >>>> >>>> Thank you in advance >>>> Stathis >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Django users" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to django-users...@googlegroups.com. >>>> >>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/django-users/f96dec5e-7f33-43d5-b48b-283460668f5an%40googlegroups.com >>>> >>>> <https://groups.google.com/d/msgid/django-users/f96dec5e-7f33-43d5-b48b-283460668f5an%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cb7f9498-97ea-4769-8638-638a101ccaf9n%40googlegroups.com.
# Generated by Django 3.2.4 on 2021-06-18 21:02 from os import name from django.db import migrations import json from django.contrib.gis.geos import fromstr from pathlib import Path DATA_FILENAME = 'data.json' def load_data(apps, schema_editor): Shop = apps.get_model('shops', 'Shop') jsonfile = Path(__file__).parents[2] / DATA_FILENAME with open(str(jsonfile)) as datafile: objects = json.load(datafile) for obj in objects['elements']: try: objType = obj['type'] if objType == 'node': tags = obj['tags'] name = tags.get('name', 'no-name') longitude = obj.get('lon', 0) latitude = obj.get('lat', 0) location = fromstr( f'POINT({longitude} {latitude})', srid=4326 ) Shop(name=name, location=location).save() except KeyError: pass class Migration(migrations.Migration): dependencies = [ ('shops', '0001_initial'), ] operations = [ migrations.RunPython(load_data) ]