Thanks, you both are right.

user_form.save() is causing the INSERT of the related UserProfile
object. The User object in question here is django.contrib.auth's User
object.

It knows about the UserProfile model object from the following line in
settings.py
AUTH_PROFILE_MODULE = 'courses.userprofile'

I can unserstand the need to create a blank UserProfile object when a
User object is created (perhaps to ensure that a User always has a
UserProfile... even if it's an empty one)

I tried to changing my code, so I update the user_profile_form after
saving the user_form. But that gives me an error because it cannot
find the related object.

Now I am in a situation where if I try to save both the forms, I get a
duplicate key error, and if I try to update the user_profile_form, the
primary key of the related User is not found. I think this may be
because the save and update are happening on the same transaction
because of the transaction middleware I am using.

Is there a good solution to this problem?

-- 
Thanks & Regards
Parag Shah
http://blog.adaptivesoftware.biz



<a...@clearwind.ca> wrote:
>
>> Why is an INSERT statement being generated even though I have
>> commit=False? The two inserts are causing an Exception which prevent
>> the actual user data from being saved (a row in the
>> courses_userprofile table does get created, but with all columns
>> except the id being blank)
>
> Its odd that the two insert statements have different values for email,
> since between the user_profile_form.save and user_profile.save, you
> arent adding the email in. As Daniel suggested, its more likely the save
> is coming from elsewhere.
>
> Install django-debug-toolbar, then click on the "explain" link on the
> SQL statement, this will tell you exactly where the statement is coming
> from.
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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