On Thu, 2010-03-25 at 15:58 +0000, Tom Evans wrote:
[...]
> 
> He is describing this situation:
> 
> >>> User.objects.get(username='tevans...@googlemail.com')
> <User: tevans...@googlemail.com>
> >>> User.objects.get_or_create(username='tevans...@googlemail.com')
> (<User: tevans...@googlemail.com>, False)
> >>> User.objects.get(username='tevans...@googlemail.com').first_name
> u'Tom'
> >>> User.objects.get(username='tevans...@googlemail.com', first_name='Thomas')
> Traceback (most recent call last):
>   File "<console>", line 1, in <module>
>   File "....site-packages/django/db/models/manager.py", line 119, in get
>     return self.get_query_set().get(*args, **kwargs)
>   File "....django/db/models/query.py", line 305, in get
>     % self.model._meta.object_name)
> DoesNotExist: User matching query does not exist.
> >>> User.objects.get_or_create(username='tevans...@googlemail.com', 
> >>> first_name='Thomas')
> Traceback (most recent call last):
>   File "<console>", line 1, in <module>
>   File "....site-packages/django/db/models/manager.py", line 122, in
> get_or_create
>     return self.get_query_set().get_or_create(**kwargs)
>   File "....site-packages/django/db/models/query.py", line 343, in 
> get_or_create
>     raise e
> IntegrityError: (1062, "Duplicate entry '' for key 2")

No, he's not, because Kenneth said that the instance exists. In your
example, the instance doesn't exist and thus a new object is attempted
to be created. The restrictions at that point are the same as when
creating a new object from scratch, as noted in my reply. The caller of
get_or_create() will always know what the various constraints are on the
model and must allow for that in their code.

Regards,
Malcolm


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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