Discussion:
solving fixture data conflicts
Evan H. Carmi
2008-03-04 06:59:37 UTC
Permalink
Hi,

I am trying to loaddata from a file, bmdata.xml and getting an error:
Problem installing fixture 'bmdata.xml': duplicate key violates unique
constraint "django_content_type_app_label_key"

I understand that there is a conflict in the fixture data. However, I
don't know how to solve it. I only ran syncdb before loaddata, and did
not create any content.

Thanks,
Evan

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Russell Keith-Magee
2008-03-04 10:07:38 UTC
Permalink
On Tue, Mar 4, 2008 at 3:59 PM, Evan H. Carmi
Post by Evan H. Carmi
Hi,
Problem installing fixture 'bmdata.xml': duplicate key violates unique
constraint "django_content_type_app_label_key"
I understand that there is a conflict in the fixture data. However, I
don't know how to solve it. I only ran syncdb before loaddata, and did
not create any content.
Hi Evan,

The catch is that you _did_ create content - you just don't know that
you did because it happens in the background. When you run syncdb,
various triggers are fired that stimulate the creation of certain
initial data. Of particular interest in this case are the content
types. Each model you have in your project generates a content type so
that the models can be referred to in a generic manner by other parts
of Django.

There isn't really any way to control the content types that are
allocated. As a result, if you change the applications that are
installed, or the order in which they are installed, the content types
can change. If you generate a fixture on an old database, modify the
installed apps, re-synchronize your database, then load your fixture,
the old content types can potentially cause a conflict - the error you
are seeing is one such potential problem.

The only real solution at present is to avoid serializing content
types whenever possible (i.e., by not dumping the contenttypes
application). If your fixture already has content types, manually
delete them from the fixture before loading.

This is a known crusty area associated with fixtures. Unfortunately,
it isn't a trivial problem to fix. Suggestions on how to improve this
aspect of Django are most welcome.

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Evan H. Carmi
2008-03-05 04:34:01 UTC
Permalink
Post by Russell Keith-Magee
The only real solution at present is to avoid serializing content
types whenever possible (i.e., by not dumping the contenttypes
application). If your fixture already has content types, manually
delete them from the fixture before loading.
How can I go about manually deleting the content types? Is there
something I should look for in my file exported with dumpdata?

Evan

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Russell Keith-Magee
2008-03-05 04:41:57 UTC
Permalink
On Wed, Mar 5, 2008 at 1:34 PM, Evan H. Carmi
Post by Evan H. Carmi
Post by Russell Keith-Magee
The only real solution at present is to avoid serializing content
types whenever possible (i.e., by not dumping the contenttypes
application). If your fixture already has content types, manually
delete them from the fixture before loading.
How can I go about manually deleting the content types? Is there
something I should look for in my file exported with dumpdata?
In an XML fixture, you are looking for any object that matches:

<object pk="59" model="contenttypes.contenttype"> .... </object>

(for any value of PK). Delete those objects (including all the tags
inside the <object> tag pair), and you should be OK.

Analogous structures exist for all the other serialization formats.
The magic bit is 'model="contenttypes.contenttype"

Yours
Russ Magee %-)

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

Continue reading on narkive:
Loading...