0

please help to solve the problem.

python3.4, django1.6. I'm trying to put the data into the database from a file initial_data.json

after the command

python manage.py syncdb --all

tables are created, but the data from the file initial_data.json will not fit into the tables. here's the console output:

(ds_d16)kalinins@kalinins-Lenovo-Z580 ~/.virtualenvs/ds_d16/django_projects/drummersaransk_new $ python manage.py syncdb --all
Syncing...
Creating tables ...
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table captcha_captchastore
Creating table thumbnail_kvstore
Creating table app_drummersaransk_city
Creating table app_drummersaransk_status
Creating table app_drummersaransk_gender
Creating table app_drummersaransk_teacher
Creating table app_drummersaransk_userprofile
Creating table app_drummersaransk_pathglory
Creating table app_drummersaransk_friends
Creating table app_drummersaransk_message
Creating table south_migrationhistory

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'kalinins'): admin
Email address: prozaik81-2@yandex.ru
Password: 
Password (again): 
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/kalinins/.virtualenvs/ds_d16/lib/python3.4/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/home/kalinins/.virtualenvs/ds_d16/lib/python3.4/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/kalinins/.virtualenvs/ds_d16/lib/python3.4/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/kalinins/.virtualenvs/ds_d16/lib/python3.4/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/home/kalinins/.virtualenvs/ds_d16/lib/python3.4/site-packages/django/core/management/base.py", line 415, in handle
    return self.handle_noargs(**options)
  File "/home/kalinins/.virtualenvs/ds_d16/lib/python3.4/site-packages/south/management/commands/syncdb.py", line 92, in handle_noargs
    syncdb.Command().execute(**options)
  File "/home/kalinins/.virtualenvs/ds_d16/lib/python3.4/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/home/kalinins/.virtualenvs/ds_d16/lib/python3.4/site-packages/django/core/management/base.py", line 415, in handle
    return self.handle_noargs(**options)
  File "/home/kalinins/.virtualenvs/ds_d16/lib/python3.4/site-packages/django/core/management/commands/syncdb.py", line 162, in handle_noargs
    database=db, skip_validation=True)
  File "/home/kalinins/.virtualenvs/ds_d16/lib/python3.4/site-packages/django/core/management/__init__.py", line 159, in call_command
    return klass.execute(*args, **defaults)
  File "/home/kalinins/.virtualenvs/ds_d16/lib/python3.4/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/home/kalinins/.virtualenvs/ds_d16/lib/python3.4/site-packages/django/core/management/commands/loaddata.py", line 55, in handle
    self.loaddata(fixture_labels)
  File "/home/kalinins/.virtualenvs/ds_d16/lib/python3.4/site-packages/django/core/management/commands/loaddata.py", line 84, in loaddata
    self.load_label(fixture_label)
  File "/home/kalinins/.virtualenvs/ds_d16/lib/python3.4/site-packages/django/core/management/commands/loaddata.py", line 134, in load_label
    for obj in objects:
  File "/home/kalinins/.virtualenvs/ds_d16/lib/python3.4/site-packages/django/core/serializers/json.py", line 65, in Deserializer
    stream_or_string = stream_or_string.read()
  File "/home/kalinins/.virtualenvs/ds_d16/lib/python3.4/codecs.py", line 313, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc2 in position 86: invalid continuation byte
dert
  • 51
  • 5
  • Your fixture file is somehow incorrect. Django expects it to be unicode input, but apparently it isn't. See also http://stackoverflow.com/questions/5552555/unicodedecodeerror-invalid-continuation-byte. –  Sep 11 '14 at 08:37

1 Answers1

0

Working with initial json data is a pita, in my experience. It is way easier to create initial values using sql inserts. Make an sql dump from your database of the initial values, and turn them into per model seperate .sql files. Place these in the folder of the right app.

So it could be something like:
- foo (your app) - sql (the sql folder *with* __init__.py) - bar.sql (your Bar model insert sql's)

Give this a try.