get_or_create shouldn't give duplicate entry error
anyone help.

On 2012/10/13, at 11:06, Wei Wei wrote:

> I am new to Django. But does the error message literally mean you have 
> duplicated records against your unique_together constriction?
> 
> On Sat, Oct 13, 2012 at 9:47 AM, Zheng Li <dllizh...@gmail.com> wrote:
> class AB(models.Model):
>     a = models.ForeignKey(A)
>     b = models.ForeignKey(B)
>     c = models.IntegerField(default=0)
>     d = models.FloatField(default=0)
>     e = models.IntegerField(default=0)
>     f = models.FloatField(default=0)
>     class Meta:
>         unique_together = (('a', 'b'),)
> 
> I have a class like above.
> when I call get_or_create, sometimes IntegrityError: (1062, "Duplicate entry) 
> error happens.
> a, _ = AB.objects.get_or_create(a=a, b=b)
> 
> I really have googled and worked on it for a while, but still nothing.
> anyone can help?
> Thanks in advance.
> 
> -- 
> 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+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 
> -- 
> 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+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to