Traceback (most recent call last):
File "/home/sector119/devel/eps_src/eps/apps/imports/management/
commands/importdata.py", line 144, in import_source
obj.save()
File "/home/sector119/devel/django_src/django/core/serializers/
base.py", line 168, in save
models.Model.save(self.object, raw=True)
File "/home/sector119/devel/django_src/django/db/models/base.py",
line 264, in save
','.join(placeholders)), db_values)
File "/home/sector119/devel/django_src/django/db/backends/util.py",
line 18, in execute
return self.cursor.execute(sql, params)
IntegrityError: duplicate key value violates unique constraint
"people_person_location_id_key"
Hi ALL!
I try to write my own comand to manage.py which imports data in some
format to the db.
I write my own serializer which yields
base.DeserializedObject(self.model(**data), m2m_data).
When I run deserlialized object save method I got IntegrityError -
because I use unique_together = ('location', 'pid') and model's data
violate unique constraint "people_person_location_id_key".
But I think that does Django have to run UPDATE not INSERT here?
My simplified Person model:
class Person(models.Model):
id = PositiveBigIntegerField(_('Global person id'),
help_text=_('Global person id: location id concatenated
with person id.'), primary_key=True)
pid = models.IntegerField(_('Person id'))
location = models.ForeignKey(Location,
verbose_name=_('Location:'))
first_name = models.CharField(_('First name'), max_length=50)
last_name = models.CharField(_('Last name'), max_length=50,
blank=True, db_index=True)
def save(self):
self.id = self._get_id()
super(Person, self).save() # Call the "real" save() method.
class Meta:
unique_together = ('location', 'pid')
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---