2
  1. python manage.py dumpdata modelName > file.json.
  2. created an empty database for a user meder on postgres
  3. modified pga_hb.conf so that meder can use the database
  4. changed the settings in settings.py
  5. python manage.py syncdb ( I didnt create a su )
  6. attempting to loaddata file.json but it complains that the superuser isn't there or doesn't match up...

    Traceback (most recent call last): File "manage.py", line 11, in execute_manager(settings) File "/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/core/management/init.py", line 438, in execute_manager utility.execute() File "/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/core/management/init.py", line 379, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/core/management/base.py", line 191, in run_from_argv self.execute(*args, **options.dict) File "/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/core/management/base.py", line 220, in execute output = self.handle(*args, **options) File "/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/core/management/commands/loaddata.py", line 219, in handle transaction.commit(using=using) File "/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/db/transaction.py", line 199, in commit connection._commit() File "/srv/python-environments/saltycrane/lib/python2.5/site-packages/django/db/backends/init.py", line 32, in _commit return self.connection.commit() psycopg2.IntegrityError: insert or update on table "bugs_bug" violates foreign key constraint "poster_id_refs_id_89e0243f" DETAIL: Key (poster_id)=(1) is not present in table "auth_user".

Was I not supposed to syncdb? Was I supposed to dumpdata for the generic tables? I still have the db all intact in MySQL but would appreciate any direction.

SIDENOTE: I do have south installed. I did the --initial command a couple days ago. Perhaps I could use south as well?

3 Answers 3

5

You have to run:

python manage.py dumpdata > file.json.

This will dump data from all tables(Models).

Running python manage.py dumpdata myapp.modelName > file.json. will only dump data for model modelName in app myapp.

You can also try, this if you only want to dump data for model modelName:

python manage.py dumpdata auth myapp.MyModel > file.json

This way data with Users will also dumped.

Sign up to request clarification or add additional context in comments.

1 Comment

perfect, I thought I had to do that but some example syntax just showed how to dump the model only so I didn't think it was possible.
3

Use

python manage.py dumpdata --natural > file.json.

More here: http://docs.djangoproject.com/en/dev/ref/django-admin/#django-admin-option---natural

1 Comment

The --natural option will tell Django to use natural keys if available.
0

long time ago after excruciating export/import jsons pains I end up using https://pypi.python.org/pypi/py-mysql2pgsql

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.