meder omuraliev
meder omuraliev

Reputation: 186562

Migrating data to Postgres from Mysql with Django - how do I migrate generic table data, not model specific?

  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?

Upvotes: 2

Views: 1877

Answers (3)

Rafael
Rafael

Reputation: 2178

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

Upvotes: 0

nicolas
nicolas

Reputation: 880

Use

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

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

Upvotes: 3

Dominik Szopa
Dominik Szopa

Reputation: 1919

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.

Upvotes: 5

Related Questions