On Thu, Apr 25, 2013 at 4:55 PM, Carsten Fuchs <[email protected]> wrote: > Hi all, > […] > In the example that works (in my original mail, not quoted here), when the > assignment is done, the Vorblendplan instance already has an id, so that it > is properly carried into ma.vbp_id. > > Can someone confirm this, is my understanding correct?
Yes, this is correct, when you assign an object to a foreign key, it must already be saved so that it has an id in order to persist in the database. The code that does this is here: https://github.com/django/django/blob/master/django/db/models/fields/related.py#L208 This is master, and you can see there is now a check in there - line 235 in master - that would have raised an exception in your example (the check is also in 1.5). In 1.4, the check is not present: https://github.com/django/django/blob/stable/1.4.x/django/db/models/fields/related.py#L259 So I guess you're using 1.4! Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.

