Closed bnord closed 8 years ago
Here's the json: [{"model": "Candidate", "pk": 1, "fields": {"Mag Min": "22.3", "Mask Blue": "7", "Image Path": "DES0042-441410208310-44133023.png", "Mag Max": "23.8", "Mask Red": "6", "Rank": "10", "SB Max": "24.55", "SB Min": "23", "Vis End": "12/5/2016", "position angle": "300", "RA": "10.20279", "Vis Start": "8/10/2016", "Dec": "-44.12075", "ID": "DESJ000-000"}}, {"model": "Candidate", "pk": 2, "fields": {"Mag Min": "22.3", "Mask Blue": "7", "Image Path": "DES0042-441410208310-44133023.png", "Mag Max": "23.8", "Mask Red": "6", "Rank": "10", "SB Max": "24.55", "SB Min": "23", "Vis End": "12/5/2016", "position angle": "300", "RA": "10.20279", "Vis Start": "8/10/2016", "Dec": "-44.12075", "ID": "DESJ001-000"}}]
Brian, I think you are just missing the name of the app when specifying the model, it should be:
[ { "model": "candidates.cantidate", ... } ]
How do we know that app is "candidates" and model is "candidate"?
In django terminology masterlist is the project name. Inside the project you can have several apps in this case we have one called candidates. Models are created per app and their names correspond to the class names in models.py
I get the error below when I try to update the db with the a json file.
└─(/usr/local/masterlist/masterlist)─(>)─ python manage.py loaddata masterlist.json Traceback (most recent call last): File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/usr/local/masterlist/env/lib/python2.7/site-packages/django/core/management/init.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/masterlist/env/lib/python2.7/site-packages/django/core/management/init.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/masterlist/env/lib/python2.7/site-packages/django/core/management/base.py", line 393, in run_from_argv
self.execute(_args, _cmd_options)
File "/usr/local/masterlist/env/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute
output = self.handle(_args, _options)
File "/usr/local/masterlist/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 60, in handle
self.loaddata(fixture_labels)
File "/usr/local/masterlist/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 90, in loaddata
self.load_label(fixture_label)
File "/usr/local/masterlist/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 141, in load_label
for obj in objects:
File "/usr/local/masterlist/env/lib/python2.7/site-packages/django/core/serializers/json.py", line 85, in Deserializer
six.reraise(DeserializationError, DeserializationError(e), sys.exc_info()[2])
File "/usr/local/masterlist/env/lib/python2.7/site-packages/django/core/serializers/json.py", line 79, in Deserializer
for obj in PythonDeserializer(objects, **options):
File "/usr/local/masterlist/env/lib/python2.7/site-packages/django/core/serializers/python.py", line 96, in Deserializer
Model = _get_model(d["model"])
File "/usr/local/masterlist/env/lib/python2.7/site-packages/django/core/serializers/python.py", line 166, in _get_model
return apps.get_model(model_identifier)
File "/usr/local/masterlist/env/lib/python2.7/site-packages/django/apps/registry.py", line 201, in get_model
app_label, model_name = app_label.split('.')
django.core.serializers.base.DeserializationError: Problem installing fixture '/usr/local/masterlist/masterlist/candidates/fixtures/masterlist.json': need more than 1 value to unpack