Saturday, July 21, 2012

Re: sqlite to mysql loaddata not working (using natural keys)

On Fri, Jul 20, 2012 at 2:57 PM, dack <dack@ereomega.net> wrote:
I'm trying to move django data from an sqlite database to a mysql database. I know I need to use natural keys, but it's still failing. Any ideas?

Here's my procedure. The default database is sqlite, the mysql database is called "mysql" in settings.py.

$./manage.py dumpdata -a -n > data.json
$./manage.py flush --database=mysql
You have requested a flush of the database.
This will IRREVERSIBLY DESTROY all data currently in the 'django' database,
and return each table to the state it was in after syncdb.
Are you sure you want to do this?

    Type 'yes' to continue, or 'no' to cancel: yes

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): no
Installed 0 object(s) from 0 fixture(s)
Note - if I examine the mysql database at this point, the tables all exist and contain 0 rows (as I expected)
$./manage.py loaddata --database=mysql ./data.json
Problem installing fixture './data.json': Traceback (most recent call last):
  File "/usr/local/lib/python2.6/site-packages/django/core/management/commands/loaddata.py", line 196, in handle
    obj.save(using=using)
  File "/usr/local/lib/python2.6/site-packages/django/core/serializers/base.py", line 165, in save
    models.Model.save_base(self.object, using=using, raw=True)
  File "/usr/local/lib/python2.6/site-packages/django/db/models/base.py", line 565, in save_base
    created=(not record_exists), raw=raw, using=using)
  File "/usr/local/lib/python2.6/site-packages/django/dispatch/dispatcher.py", line 172, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/genpool0/db/foo/intranet/../intranet/userprofile/models.py", line 22, in create_user_profile
    UserProfile.objects.create(user=instance)

You've got app code running here that is forcing creation of a UserProfile when the user is loaded. Likely these UserProfile objects are also being loaded from the fixture, so the attempt to create them is generating the "user_id" is not unique error.

Karen
--
http://tracey.org/kmt/

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment