我试图将模型A复制到模型B,但是由于某种原因,我遇到了唯一约束失败:appname_duplicate.id
Class orignal(models.Model):
managed = True
[some_fields]
def __unicode__(self):
return self.recipient_email
Class duplicate(models.Model):
managed = True
[same_as_Orignal_fields]
def __unicode__(self):
return self.recipient_email
功能:
def clone_orignal(source, destination):
duplicate = list()
for row in source.objects.all().values():
if row not in duplicate:
duplicate.append(destination(**row))
if duplicate:
destination.objects.bulk_create(duplicate)
有人可以看看吗?