.create() creates the object into DB, then .save(force_insert=True)
tries to insert the same object with the same ID again -> integrity
error. Seems like you don't need the second save at all.
- Anssi
On 27 syys, 15:39, Amyth Arora <aroras.offic...@gmail.com> wrote:
> Not quite sure, but it seems like the save() method is being called twice
> so it is trying to create insert an entry with a primary key that already
> exists.
>
>
>
>
>
>
>
>
>
> On Thu, Sep 27, 2012 at 2:23 PM, enemybass <dominikan...@gmail.com> wrote:
> > http://wklej.org/id/837631/- models, traceback, urls, views, database
> > structure
>
> > After adding data to database I have error (data is added correctly but
> > displays an error):
>
> > Exception Type: IntegrityError at /add/Exception Value: PRIMARY KEY must be unique
>
> > def add(request):
> > if request.user.is_authenticated():
> > user = request.user
> > b = Product.objects.get(id=3)
> > e = b.basket_set.create(name='basket_name', owner=user)
> > e.save(force_insert=True)
>
> > return render_to_response('basket.html')
>
> > How to fix it?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To view this discussion on the web visit
> >https://groups.google.com/d/msg/django-users/-/mdIBvzeje1gJ.
> > 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.
>
> --
> Thanks & Regards
> ----------------------------
>
> Amyth [Admin - Techstricks]
> Email - aroras.offic...@gmail.com, ad...@techstricks.com
> Twitter - @mytharorahttp://techstricks.com/
--
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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment