I'm trying to import initial data into my Django application. I have several tables, but I'd like to import them one by one.
I decided to begin with the simplest table:
class ClientRun(models.Model):
start_time = models.BigIntegerField()
end_time = models.BigIntegerField()
ip = models.GenericIPAddressField()
country = models.CharField(max_length=255)
def __unicode__(self):
return str(self.start_time) + " " + str(self.end_time)
And I manually created a fixture file:
[
{
"model": "georoute.clientrun",
"pk": 1,
"fields": {
"ip": "0.0.0.0",
"start_time": 0,
"end_time": 0,
"country": "ZZ"
}
},
]
When I run
python manage.py loaddata shengy_clientrun.json
it returns:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/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/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 60, in handle
self.loaddata(fixture_labels)
File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 90, in loaddata
self.load_label(fixture_label)
File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 141, in load_label
for obj in objects:
File "/usr/local/lib/python2.7/site-packages/django/core/serializers/json.py", line 84, in Deserializer
six.reraise(DeserializationError, DeserializationError(e), sys.exc_info()[2])
File "/usr/local/lib/python2.7/site-packages/django/core/serializers/json.py", line 78, in Deserializer
for obj in PythonDeserializer(objects, **options):
File "/usr/local/lib/python2.7/site-packages/django/core/serializers/python.py", line 109, in Deserializer
for (field_name, field_value) in six.iteritems(d["fields"]):
django.core.serializers.base.DeserializationError: Problem installing fixture '/Users/shengy/Dropbox/shengy/code/django_tutorial/gae_site/georoute/fixtures/shengy_clientrun.json': u'fields'
I double-checked the JSON format, and the database is now empty. I'm using MySQL as the backend database.
Your fixture is not valid JSON. Unlike Python, JSON cannot have trailing commas.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With