In details:
{{{
class ReferencedObj(Model):
...
class ReferencingObj(Model):
referenced_obj = ForeignKey(ReferencedObj)
...
x = ReferencedObj()
y = ReferencingObj()
y.referenced_obj = x
x.save()
y.save() -----→ NOT NULL constraint failed:
..._referencingobj.referenced_obj_id
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30537>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> In short: if referenced obj. is saved after attaching to a referencing
> obj. its id field (i.e. ''<refrerenced_obj>''_id) there remains None.
>
> In details:
>
> {{{
> class ReferencedObj(Model):
> ...
>
> class ReferencingObj(Model):
>
> referenced_obj = ForeignKey(ReferencedObj)
> ...
>
> x = ReferencedObj()
> y = ReferencingObj()
>
> y.referenced_obj = x
>
> x.save()
>
> y.save() -----→ NOT NULL constraint failed:
> ..._referencingobj.referenced_obj_id
> }}}
New description:
In short: if referenced obj. is saved after attaching to a referencing
obj. its id field (i.e. ''<refrerenced_obj>''_id) there remains None.
In details:
{{{
class ReferencedObj(Model):
...
class ReferencingObj(Model):
referenced_obj = ForeignKey(ReferencedObj)
...
x = ReferencedObj()
y = ReferencingObj()
y.referenced_obj = x
x.save()
y.save() -----→ NOT NULL constraint failed:
..._referencingobj.referenced_obj_id
}}}
Thats happens because **referenced_obj_id** field is not bound to the
underlying **referenced_obj.id**
--
--
Ticket URL: <https://code.djangoproject.com/ticket/30537#comment:1>
* status: new => closed
* resolution: => duplicate
Comment:
Duplicate of #28147.
--
Ticket URL: <https://code.djangoproject.com/ticket/30537#comment:2>